:: Home

  login:         
  passwords:  

OOP Interview Questions and answers [Part 3]

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

3. OOP Interview Questions and FAQs [Part 3]

    3.1 What is virtual constructors/destructors?
    3.2 What is the difference between declaration and definition?
    3.3 When is a memory allocated to a class?
    3.4 What are the advantages of inheritance?
    3.5 What do you mean by pure virtual functions?
    3.6 Why do we use virtual functions?
    3.7 What is the difference between pass by reference and pass by value?
    3.8 What are generic functions and generic classes?
    3.9 What is a template?
    3.10 Difference between realloc() and free?
    3.11 When is an object created and what is its lifetime?
    3.12 What do you mean by inline function?
    3.13 What is virtual class and friend class?
    3.14 What is abstraction?
    3.15 What is a scope resolution operator?
    3.16 What is friend function?
    3.17 What is the difference between class and structure?
    3.18 What is a class?
    3.19 what is object slicing?
    3.20 Why and when is a virtual destructor needed? /a>

3.1 What is virtual constructors/destructors?

virtual constructors are used when we need to avoid the copy same. desructor frees the memory with a ~(tilde) symbol


3.2 What is the difference between declaration and definition?

During declaration we just specify the type and no memory is allocated to the variable. But during the definition an initial value is assigned and memory is allocated to the variable.


3.3 When is a memory allocated to a class?

When instance of that class is creater by us


3.4 What are the advantages of inheritance?

In OOPs, the concept of inheritance provides the idea of reusability. This means that we can add additional features to an existing class without modifying it. This is possible by deriving a new class from the existing one. The new class will have combined features of both the classes.


3.5 What do you mean by pure virtual functions?

A pure virtual function is a function that must be overridden in a derived class and need not be defined. A virtual function is declared to be "pure" using the curious "=0" syntax: class Base { public: void f1(); // not virtual virtual void f2(); // virtual, not pure virtual void f3() = 0; // pure virtual };


3.6 Why do we use virtual functions?

The virtual function can be allowed in base classes only. The functions marked Virtual will only be override able in derived classes. If i m having a function in base class that should come in derived class but i want it to have different behavior. This can only be achieved only if base class function is virtual function.


3.7 What is the difference between pass by reference and pass by value?

in pass by referance the parameters are passed as the address of the variables whereas in pass by value the variables are directly passed as parameters


3.8 What are generic functions and generic classes?

Generic functions are functions which are not used for any particular datatype..they are useful for anydatatype Ex: if you write code for the Sorting program using templates then the function is useful for any data type


3.9 What is a template?

The template specifies a set of parameterized classes or functions.


3.10 Difference between realloc() and free?

realloc(): memory when gets decreased, we can allocate it with the function called realloc(). free: it is used to free the memory in the program.


3.11 When is an object created and what is its lifetime?

whenever developer is required, and the life-time is when we assinging null or close the program(application).


3.12 What do you mean by inline function?

The __inline keyword tells the compiler to substitute the code within the function definition for every instance of a function call. However, substitution occurs only at the compiler’s discretion. For example, the compiler does not inline a function if its address is taken or if it is too large to inline.


3.13 What is virtual class and friend class?

friend class are used when two or more classes are designed to work together and virtual base class aids in multiple inheritance


3.14 What is abstraction?

Abstraction is thing which you directly not use. like as in motor making all spare aprart are come from differnt class which all are combined in one motor class where we use it. we direclty not use any only one think as tyre or petrol for use it we want to combine that all.


3.15 What is a scope resolution operator?

when a function is declared inside the class, it can be used or imlemented with the operator called scope resolution operator with a :: symbol.


3.16 What is friend function?

It is a non-member function, but having access to class members.


3.17 What is the difference between class and structure?

structure is a value type class is reference type, struct Memory will be on stack and class Memory stored on Heap, struct not suports inheritance and class can? By default the members of struct are public. By default the members of class are priavte. When an object is created to a class, constructor will be called automatically. But not in struct (if structure having member function with structure name)


3.18 What is a class?

A class is a logical existence of a data containing data variables and member functions having relations between them.


3.19 what is object slicing?

When an base class is assinged to its derived class the base class takes up only the base member data leaving the data members of derived class.this is called object slicing


3.20 Why and when is a virtual destructor needed?

Any class that may act as the base of another class should have a virtual destructor. This ensures that when an object of the derived class is destroyed that the derived class dtor will be invoked to destroy it. If the destructor is not virtual, under some common circumstances, only the base class' destructor will be invoked, regardless of the class actually being destroyed. For practical purposes this means that a class which does, could or should have virtual member functions, should also have a virtual destructor.

Copyright 2007, Megasolutions Ltd