Interview Questions
OOPS Concepts · Study material
C++ OOPS Concepts – Interview Questions
1. What is object-oriented programming?
A programming paradigm that organises software as objects combining data and behaviour, built on encapsulation, abstraction, inheritance and polymorphism.
2. What is the difference between a class and an object?
A class is a type – a blueprint describing data and functions. An object is a concrete instance of that class occupying memory, with its own values.
3. What is encapsulation?
Bundling data with the functions that operate on it and restricting direct access to the data (private members), so the class controls how its state changes.
4. What is abstraction, and how is it different from encapsulation?
Abstraction exposes only the essential interface and hides implementation details (abstract classes, interfaces). Encapsulation is the mechanism of hiding the data itself. Abstraction is about design, encapsulation about implementation.
5. What is inheritance? Name its types.
Deriving a class from another to reuse and extend it. Types: single, multiple, multilevel, hierarchical and hybrid.
6. What is polymorphism? Name its types.
The ability of one interface to work with different types. Compile-time: function overloading, operator overloading, templates. Run-time: virtual functions with dynamic binding.
7. What is the difference between overloading and overriding?
Overloading: same name, different parameters, in the same scope, resolved at compile time. Overriding: a derived class redefines a base virtual function with the same signature, resolved at run time.
8. What is a virtual function?
A member function declared virtual in a base class, whose call through a base pointer or reference is dispatched to the most-derived override at run time.
9. What is a pure virtual function and an abstract class?
A pure virtual function is declared with = 0 and has no required implementation; a class containing one is abstract and cannot be instantiated.
10. What is a vtable?
A per-class table of pointers to virtual function implementations; each polymorphic object holds a hidden pointer (vptr) to its class's table, used to dispatch virtual calls.
11. Why does a base class need a virtual destructor?
Without it, deleting a derived object through a base pointer calls only the base destructor – undefined behaviour and usually a resource leak.
12. What is the this pointer?
An implicit pointer, available in non-static member functions, to the object on which the function was called.
13. What is a static member?
A data member shared by all objects of a class, or a member function that belongs to the class and has no this pointer.
14. What is the difference between composition and inheritance?
Composition is HAS-A (a class contains objects of other classes); inheritance is IS-A. Composition gives looser coupling and is usually preferred unless polymorphic substitution is needed.
15. What is object slicing?
When a derived object is copied into a base object by value, the derived part is cut off; virtual calls on the copy use the base implementation.
16. What are access specifiers?
public, protected and private – they control which code may access class members.
17. What is the difference between struct and class in C++?
Default access: public for struct, private for class (both for members and base classes). Otherwise they are identical.
18. What is dynamic binding?
Choosing which function body to execute at run time based on the actual object type, as with virtual function calls.
19. What is a friend function?
A non-member function granted access to a class's private and protected members by a friend declaration inside the class. It weakens encapsulation and should be used sparingly (e.g. operator<<).
20. What are the SOLID principles?
Single responsibility, open/closed, Liskov substitution, interface segregation and dependency inversion – guidelines for maintainable object-oriented design.