Email: Password:       Forgot Password 
    .netCodeSG
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.
 
TECHNOLOGIES:
 

OOPS Interview Questions and Answers

Article:
Viewed:  1575 
Posted On:  03/05/2013 12:45:55 
Most general question of OOPS asked in interview. 

 

1. What is OOPS?
OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

2. Write basic concepts of OOPS?
Following are the concepts of OOPS and are as follows:.

          Abstraction.
          Encapsulation.
          Inheritance.
          Polymorphism.

3. What is a class?
Class is a collection of the object, and it has common structure and behaviour.

4. What is an object?
Object is termed as an instance of a class, and it has its own state, behaviour and identity.

5. What is Encapsulation?
Encapsulation is an attribute of an object, and it contains all data which is hidden. That hidden data can be restricted to the members of that class. Levels are Public, Protected, Private, Internal and Protected Internal.

6. What is Polymorphism?
Polymorphism is nothing but assigning behaviour or value in a subclass to something that was already declared in the main class. Simply, polymorphism takes more than one form.


7. What is Inheritance?
Inheritance is a concept where one class shares the structure and behaviour defined in another class. If inheritance applied on one class is called Single Inheritance, and if it depends on multiple classes, then it is called multiple Inheritance.

8. What is the difference between arrays and collection?
Array:          1. You need to specify the size of an array at the time of its declaration. It cannot be resized dynamically.
             2. The members of an array should be of the same data type.

Collection:   1. The size of a collection can be adjusted dynamically, as per the user's requirement. It does not have fixed size.
             2. Collection can have elements of different types.
 

9. Define a constructor?
Constructor is a method used to initialize the state of an object, and it gets invoked at the time of object creation. Rules for constructor are:.

          Constructor Name should be same as class name.
          Constructor must have no return type.

10. Define Destructor?
Destructor is a method which is automatically called when the object is made of scope or destroyed. Destructor name is also same as class name but with the tilde symbol before the name.

11. What is Inline function?
Inline function is a technique used by the compilers and instructs to insert complete body of the function wherever that function is used in the program source code.


12. What is a virtual function?
Virtual function is a member function of class and its functionality can be overridden in its derived class. This function can be implemented by using a keyword called virtual, and it can be given during function declaration. 

13. What is friend function?
Friend function is a friend of a class that is allowed to access to Public, private or protected data in that same class. If the function is defined outside the class cannot access such information. Friend can be declared anywhere in the class declaration, and it cannot be affected by access control keywords like private, public or protected.

14. What is function overloading?
Function overloading is defined as a normal function, but it has the ability to perform different tasks. It allows creation of several methods with the same name which differ from each other by type of input and output of the function. 

15. What is operator overloading?
Operator overloading is a function where different operators are applied and depends on the arguments. Operator,-,* can be used to pass through the function , and it has their own precedence to execute. 

16. What is an abstract class?
An abstract class is a class which cannot be instantiated. Creation of an object is not possible with abstract class , but it can be inherited. An abstract class can contain only Abstract method.

17. What is the use of finalize method?
Finalize method helps to perform cleanup operations on the resources which are not currently used. Finalize method is protected , and it is accessible only through this class or by a derived class.

18. What is method overriding?
Method overriding is a feature that allows sub class to provide implementation of a method that is already defined in the main class. This will overrides the implementation in the superclass by providing the same method name, same parameter and same return type.

19. What is an interface?
An interface is a collection of abstract method. If the class implements an inheritance, and then thereby inherits all the abstract methods of an interface.

20. Difference between overloading and overriding?
Overloading is static binding whereas Overriding is dynamic binding. Overloading is nothing but the same method with different arguments , and it may or may not return the same value in the same class itself. Overriding is the same method names with same arguments and return types associates with the class and its child class. 

21. What is an abstraction?
Abstraction is a good feature of OOPS , and it shows only the necessary details to the client of an object. Means, it shows only necessary details for an object, not the inner details of an object. Example – When you want to switch On television, it not necessary to show all the functions of TV. Whatever is required to switch on TV will be showed by using abstract class.

22. What is sealed modifiers?
Sealed modifiers are the access modifiers where it cannot be inherited by the methods. Sealed modifiers can also be applied to properties, events and methods. This modifier cannot be applied to static members. 

23. What is the difference between new and override?
The new modifier instructs the compiler to use the new implementation instead of the base class function. Whereas, Override modifier helps to override the base class function.

24. When to use Interface over abstract class? l

Abstract Classes: Classes which cannot be instantiated. This means one cannot make a object of this class or in other way cannot create object by saying

 ClassAbs abs = new ClassAbs();

where ClassAbs is abstract class.

Abstract classes contains have one or more abstarct methods, ie method body only no implementation.

Interfaces: These are same as abstract classes only difference is we can only define method definition and no implementation.

When to use wot depends on various reasons. One being design choice.

One reason for using abstarct classes is we can code common

functionality and force our developer to use it. I can have a complete

class but I can still mark the class as abstract.

Developing by interface helps in object based communication.


25. What are the various types of Constructors

Public : Accessible to All

Private: Those classes in which only static members are there and you don't want there objects to be created in any class.

Static: Used for initializing only the static members of the class. These will be invoked for the very first time the class is being loaded on the memory. They cannot accept any arguments. Static Constructors cannot have any access modifiers.

Intern: implementations of the abstract class to the assembly defining the class. A class containing an internal constructor cannot be instantiated outside of the assembly (Namespace). 
and External

  Comment:
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us