:: Home

  login:         
  passwords:  

OOP Interview Questions and answers [Part 1]

The General Oop Interview Questions consists the most frequently asked questions in Oop. This list of 100+ questions guage your familiarity with the Oop . The q&a have been collected over a period of time from various blogs, forums and other sites

1. OOP Interview Questions and FAQs [Part 1]

    1.1 Explain polymorphism? What r the types of polymorphism?
    1.2 What is the difference b/w abstract and interface?
    1.3 What is the Advantage of Interface over the Inheritance in OOPS?
    1.4 What is the difference between class and object?
    1.5 What is abstract class ? when is used in real time ?
    1.6 What is a virtual class?
    1.7 Why destructor is not over loaded?
    1.8 What is difference between overloading and overriding?
    1.9 What is the difference between new and malloc?
    1.10 Different types of castings
    1.11 What is the use of mutable key word?
    1.12 What is a copy constructor?
    1.13 What is the function of 'this' operator ?
    1.14 What is Iteration Hierarchy? What is what is Object behavioral concept?
    1.15 What is a ststic variable and stitic function?
    1.16 What is the virtual function overhead, and what is it used for ?
    1.17 What is Difference between new operator and operator new?
    1.18 What is extreme programming?
    1.19 What is Agile methodology?
    1.20 What are the different forms of polymorphism?

1.1 Explain polymorphism? What r the types of polymorphism?

Polymorphrism means the "Many forms", is feature that allows one interface to be used for a general class of actions. The specifc action is determined by the nature of the situation.
Two types of polymorphrism,
1. Compile time (Operator/Functional overloading) [Language 'C' supported
polymorphrism]. 2. Run time (Virtual function).
Example:
//function prototype
int Addition(int iOperand1, int iOperand2);
float Addition(float fOperand1, float fOperand2);
float Addition(int iOperand1, float fOperand2);


1.2 What is the difference b/w abstract and interface?

Abstract can,t support multiple inheritence.
Interface can suppport the multiple inheritence.
Abstract have accesbulity modifiers.
Interface have no accesbulity modifiers.


1.3 What is the Advantage of Interface over the Inheritance in OOPS?

1. Provides flexibility in implementing the operations for the derived classes.
2. Avoid conflicts when more than one interfaces are derived in a class.


1.4 What is the difference between class and object?

Class:class ia a blueprint or prototype from which object are created
Object: Object is a Software bundles of related state and behavior.


1.5 What is abstract class ? when is used in real time ?

An Abstract Class is one in which the member function(s) at the Base(Parent) Class are left undefined, but declared. It's upto the Derived(child(ren)) Classes to Implement the Functions declared in Base...
Ex:
Let us assume... As a father(Base Class), he has some Land (Member Function), and he has not done any cultivation (implementation) in it... As his Child(Derived Class), he takes the Land(Member Function) from the Father(Base) and does Agriculture(implementing the M.F. of Parent Class) in the Child...


1.6 What is a virtual class?

In multiple inheritance when a class D is derived by two base classes B and C and both base class is also inherite by same class A then then class D will get duplicate copy of uppper most base class A.In this case class A will declare as virtual class


1.7 Why destructor is not over loaded?

Normally (in fact almost always) you never explicitly call the destructor, it is automatically called by the C++ frame work when the object is deleted/goes out of scope. Therefore you would not need to overload the destructor because the frame work always calls the default destructor. Additionally the C++ standard defines that a conforming compiler only allows for 1 destructor per class.


1.8 What is difference between overloading and overriding?

in overloading methods can have the same name but must have different parameter lists i.e signature while in overriding if you declare a field in a subclass with the same name as one in the superclass, the superclass field can only be accessed using super or the superclasses type


1.9 What is the difference between new and malloc?

both malloc and new functions are used for dynamic memory allocations and the basic difference is: malloc requires a special "typecasting" when it allocates memory for eg. if the pointer used is the char pointer then after the processor allocates memory then this allocated memory needs to be typecasted to char pointer i.e (char*).but new does not requires any typecasting. Also, free is the keyword used to free the memory while using malloc and delete the keyword to free memory while using new, otherwise this will lead the memory leak.
Answer2:
new automatically calls the constructor while malloc() dosen't., also new being an operator, it can be overloaded. since malloc returns a void pointer it is necessary to explicitly typecast it into an appropriate type of pointer. This gets completely avoided when we are using new operator


1.10 Different types of castings

2 types of casting
1] Implicit casting
2] Explicit casting
   (a)Const Cast,
   (b)Static cast,
   (c)reinterprit cast,
   (d)dynamic cast;


1.11 What is the use of mutable key word?

This keyword can only be applied to non-static and non- const data members of a class. If a data member is declared mutable, then it is legal to assign a value to this data member from a const member function. if u write a class do u write Assignment operator and copy constructor Compiler provide the assignment operator/ copy constructor by default. The assignment operator and copy constructor do the bit wise copy of the object. If user want to do the member wise copy(ex:allocating the memory from the heap) for the members, one can write his/her own assignment operator/ copy constructor.


1.12 What is a copy constructor?

A copy constructor is a special constructor in the C++ programming language used to create a new object as a copy of an existing object. There are 3 important places where a copy constructor is called.
When an object is created from another object of the same type
When an object is passed by value as a parameter to a function
When an object is returned from a function


1.13 What is the function of 'this' operator ?

this' is used to reffer current class variable
for example
class sample
{
int myvar=10;
void mymethod()
{
int myvar=20;
system.outprintln("The value of myvar is"+myvar)
system.outprintln("The value of myvar is"+this.myvar)
}
}


1.14 What is Iteration Hierarchy? What is what is Object behavioral concept?

Iteration heirarchi is means looping.In c++ everything is based on Object.Object is the reference to the class.


1.15 What is a ststic variable and static function ?

Static variable is the one allocated statically, meaning that, it is allocated once in the program space and exists till the program space is deallocated (the close of the application).
Note:- Some people get confused between stack allocation and static allocaion. Both are different terms.
A static function is again the same concept with static variable allocation, but here the allocation is not just a variable but a function's 'activation frame'. The activation frame, for now, consider the function's information required by the compiler to execute the function which is stored internally.


1.16 What is the virtual function overhead, and what is it used for ?

when use hybride inhertance,virual function avoid the ambiguity.
Answer2:
I thnk virtual fns r declared with 'virtual' keyword nd it must be redifend in the derivd classes. wen mor dan one classes derivs a methd in the base class, dat method can be writn with virtual to avoid ambiguity.


1.17 What isDifference between new operator and operator new?

The "new" operator allocates a new instance of an object from the heap, utilising the most appropriate constructor for the arguments passed. Like many operators in C++, the "new" operator for a particular class can be overriden, although there is rarely a need to do so. "operator new" is the mechanism for overriding the default heap allocation logic. Ask your interviewer to provide you with a concrete example of when he or she has been required to do this.


1.18 What is extreme programming?

Extrem programming is a software developing methodology which make the rapid development possible. Key elements: pair programming (working in pair), test driven development (unit test), prototyping (make prototype and continue the development based on feedbacks)


1.19 What is Agile methodology?

Agile methodology is anadaptaive methodology, its people oriented.
Here are some of the other characteristices of the Agile methodology.
1. Delivery frequently.
2. Good ROI for client.
3. Test frequently.
4. Collaborative approach.


1.20 What are the different forms of polymorphism?

1). Operator overloading.
(2). Function overloading.
(3). Virtual functions.

Copyright 2007, Megasolutions Ltd