1. What is Object-Oriented Programming (OOP)?
Object-Oriented Programming (OOP) is a programming paradigm based on the concept of objects. It organizes software design around data (objects) rather than functions and logic. OOP helps in modularity, reusability, and maintainability of code.
2. What is a Class?
A class is a blueprint or template used to create objects. It defines properties (variables) and behaviors (methods/functions) that the objects will have.
3. What is an Object?
An object is an instance of a class. It represents a real-world entity and contains data (attributes) and methods (functions).
4. What are the components of a class?
A class typically contains:
- Variables (Attributes/Data Members)
- Methods (Functions/Behaviors)
- Constructors
- Access Modifiers
5. What is a Constructor?
A constructor is a special method that is automatically called when an object is created. It is used to initialize the object’s data members.
6. What is a Destructor?
A destructor is a special method used to release resources when an object is destroyed.
7. What is the difference between a class and an object?
A class is a blueprint, while an object is a real instance created from that blueprint.
8. What is a method?
A method is a function defined inside a class that describes the behavior of an object.
9. What is an instance variable?
An instance variable is a variable defined inside a class but outside methods. Each object gets its own copy.
10. What is a static variable?
A static variable belongs to the class rather than the object. It is shared among all instances of the class.
11. What is a static method?
A static method belongs to the class and can be called without creating an object.
12. What is the purpose of the βthisβ keyword?
The βthisβ keyword refers to the current object of the class.
13. Can a class exist without objects?
Yes, a class can exist without creating objects. It is just a blueprint until instantiated.
14. Can an object exist without a class?
No, an object must be created from a class.
15. What is object initialization?
Object initialization is the process of assigning initial values to the object’s attributes.
SECTION 2: INHERITANCE
16. What is Inheritance?
Inheritance is a mechanism where one class acquires the properties and behaviors of another class.
17. What is a parent class?
A parent class (superclass) is the class whose properties are inherited.
18. What is a child class?
A child class (subclass) is the class that inherits properties from another class.
19. What are the types of inheritance?
- Single Inheritance
- Multiple Inheritance
- Multilevel Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
20. What is Single Inheritance?
Single inheritance means a child class inherits from one parent class.
21. What is Multilevel Inheritance?
Multilevel inheritance occurs when a class inherits from a class which itself inherits from another class.
22. What is Hierarchical Inheritance?
Multiple classes inherit from a single parent class.
23. What is Multiple Inheritance?
A class inherits from more than one parent class.
24. What is the advantage of inheritance?
Code reusability, reduced redundancy, and better organization.
25. What is method overriding?
Method overriding occurs when a child class provides a specific implementation of a method already defined in the parent class.
26. What is super keyword?
The super keyword refers to the parent class object.
27. Can private members be inherited?
Private members are inherited but cannot be directly accessed.
28. What is the use of protected access modifier?
Protected members can be accessed within the same package and by subclasses.
29. What is virtual inheritance?
Virtual inheritance prevents duplication of data members when multiple inheritance is used.
30. What is the Diamond Problem?
The diamond problem occurs in multiple inheritance when two parent classes have a common base class.
SECTION 3: POLYMORPHISM
31. What is Polymorphism?
Polymorphism means “many forms”. It allows one interface to be used for different data types.
32. Types of Polymorphism?
- Compile-time (Method Overloading)
- Runtime (Method Overriding)
33. What is Method Overloading?
Method overloading allows multiple methods with the same name but different parameters.
34. What is Method Overriding?
Method overriding allows a subclass to provide a specific implementation of a parent class method.
35. What is operator overloading?
Operator overloading allows operators to have different meanings based on context.
36. What is dynamic binding?
Dynamic binding means method calls are resolved at runtime.
37. What is static binding?
Static binding means method calls are resolved at compile time.
38. Why is polymorphism important?
It increases flexibility and reusability of code.
39. Can constructors be overloaded?
Yes, constructors can be overloaded.
40. Can constructors be overridden?
No, constructors cannot be overridden.
SECTION 4: ENCAPSULATION
41. What is Encapsulation?
Encapsulation is wrapping data and methods into a single unit (class).
42. Why is encapsulation important?
It protects data from unauthorized access.
43. How is encapsulation achieved?
By declaring variables as private and providing public getter and setter methods.
44. What are access modifiers?
- Public
- Private
- Protected
- Default
45. What is a getter method?
A method used to retrieve private data.
46. What is a setter method?
A method used to modify private data.
47. What is data hiding?
Data hiding restricts access to internal object details.
48. What is immutable class?
An immutable class is a class whose objects cannot be modified after creation.
49. What is tight coupling?
Tight coupling means classes are highly dependent on each other.
50. What is loose coupling?
Loose coupling means classes are independent and flexible.
SECTION 5: ABSTRACTION
51. What is Abstraction?
Abstraction hides internal implementation details and shows only essential features.
52. How is abstraction achieved?
Through abstract classes and interfaces.
53. What is an abstract class?
An abstract class cannot be instantiated and may contain abstract methods.
54. What is an abstract method?
An abstract method has no body and must be implemented by subclasses.
55. What is an interface?
An interface is a blueprint of a class that contains abstract methods.
56. Difference between abstract class and interface?
Abstract class can have implemented methods; interface usually contains only abstract methods (language dependent).
57. Can we create object of abstract class?
No, we cannot directly create an object of abstract class.
58. Why use abstraction?
To reduce complexity and increase security.
59. What is real-world example of abstraction?
Using ATM machine without knowing internal banking process.
60. What is interface inheritance?
A class can implement multiple interfaces.
ADVANCED OOP QUESTIONS
61. What is SOLID principle?
SOLID is a set of five design principles for writing maintainable OOP code.
62. What is Single Responsibility Principle?
A class should have only one reason to change.
63. What is Open/Closed Principle?
Software entities should be open for extension but closed for modification.
64. What is Liskov Substitution Principle?
Subclasses should be replaceable with their base classes.
65. What is Interface Segregation Principle?
Clients should not depend on methods they do not use.
66. What is Dependency Inversion Principle?
Depend on abstractions, not on concrete implementations.
67. What is composition?
Composition means one class contains an object of another class.
68. Difference between composition and inheritance?
Inheritance is “is-a” relationship; composition is “has-a” relationship.
69. What is association?
Association represents relationship between classes.
70. What is aggregation?
Aggregation is a weak form of association.
71. What is strong reference?
A strong reference prevents object from garbage collection.
72. What is weak reference?
A weak reference allows object to be garbage collected.
73. What is deep copy?
Deep copy creates a new object with copied values.
74. What is shallow copy?
Shallow copy copies references.
75. What is object cloning?
Object cloning creates duplicate object.
76. What is the Factory Design Pattern?
The Factory Pattern is a creational design pattern that provides an interface for creating objects but allows subclasses to alter the type of objects that will be created. It promotes loose coupling by eliminating the need to bind application-specific classes into code.
77. What is the Singleton Design Pattern?
The Singleton Pattern ensures that a class has only one instance and provides a global access point to that instance. It is commonly used for database connections, logging, and configuration management.
78. What is the Observer Pattern?
The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified automatically.
79. What is the MVC Pattern?
MVC (Model-View-Controller) is an architectural pattern that separates an application into three components: Model (data), View (UI), and Controller (logic handling).
80. What is object lifecycle?
The object lifecycle includes object creation, memory allocation, initialization, usage, and destruction or garbage collection.
81. What is Garbage Collection?
Garbage Collection is an automatic memory management process that frees memory occupied by objects no longer in use.
82. What is the final keyword?
The final keyword is used to restrict modification. A final class cannot be inherited, a final method cannot be overridden, and a final variable cannot be changed.
83. What is a sealed class?
A sealed class restricts which other classes may inherit from it. It provides better control over inheritance hierarchy.
84. What is method hiding?
Method hiding occurs when a subclass defines a method with the same name as a static method in the parent class.
85. What is covariant return type?
Covariant return type allows a method to return a subclass type instead of the parent class type.
86. What is dynamic dispatch?
Dynamic dispatch is the process of selecting which implementation of a polymorphic operation to call at runtime.
87. What is reflection in OOP?
Reflection is the ability of a program to inspect and modify its structure and behavior at runtime.
88. What is serialization?
Serialization is the process of converting an object into a byte stream for storage or transmission.
89. What is deserialization?
Deserialization is converting a byte stream back into an object.
90. What is dependency injection?
Dependency Injection is a technique where an object receives its dependencies from an external source rather than creating them itself.
91. What is loose coupling?
Loose coupling refers to minimizing dependencies between classes to make systems more flexible and maintainable.
92. What is tight coupling?
Tight coupling means classes are highly dependent on each other, reducing flexibility.
93. What is a marker interface?
A marker interface is an empty interface used to mark or tag a class.
94. What is composition over inheritance?
It is a design principle that favors using composition (has-a relationship) instead of inheritance (is-a relationship) for flexibility.
95. What is object pooling?
Object pooling is a performance optimization technique where a set of initialized objects is kept ready to use.
96. What is late binding?
Late binding means method call resolution happens at runtime.
97. What is early binding?
Early binding means method call resolution happens at compile time.
98. What is a virtual method?
A virtual method is a method that can be overridden in a subclass to achieve runtime polymorphism.
99. What is an override keyword?
The override keyword indicates that a method overrides a method in the base class.
100. What is method overloading vs overriding?
Overloading occurs within the same class with different parameters. Overriding occurs in subclass with same method signature.
101. What is abstraction barrier?
An abstraction barrier hides internal implementation details from the outside world.
102. What is interface segregation?
It states that no client should be forced to depend on methods it does not use.
103. What is class cohesion?
Cohesion refers to how closely related the responsibilities of a class are.
104. What is coupling in OOP?
Coupling refers to the degree of interdependence between classes.
105. What is a base class?
A base class is the parent class from which other classes inherit.
106. What is a derived class?
A derived class is a class that inherits from another class.
107. What is a pure virtual function?
A pure virtual function is a function declared in a base class that must be implemented by derived classes.
108. What is method chaining?
Method chaining allows calling multiple methods on the same object in a single statement.
109. What is fluent interface?
A fluent interface is a style of API design that allows method chaining for readability.
110. What is immutable object?
An immutable object cannot be changed after it is created.
111. What is mutable object?
A mutable object can be modified after creation.
112. What is polymorphic variable?
A polymorphic variable is a reference variable of parent class type that refers to child class object.
113. What is upcasting?
Upcasting is converting a subclass reference into a superclass reference.
114. What is downcasting?
Downcasting is converting a superclass reference back to a subclass reference.
115. What is diamond problem solution?
It can be solved using virtual inheritance or interfaces depending on language.
116. What is method signature?
Method signature includes method name and parameter list.
117. What is overloading resolution?
Overloading resolution determines which overloaded method to call based on parameters.
118. What is shadowing?
Shadowing occurs when a variable in a subclass has the same name as in the parent class.
119. What is encapsulated API?
An encapsulated API exposes only necessary methods while hiding internal logic.
120. Why are OOP concepts important in interviews?
OOP concepts form the foundation of modern programming languages. Interviewers test understanding of design, scalability, maintainability, and problem-solving using OOP principles.
π’ Join Our WhatsApp Channel
πΌ Get Daily IT Job Updates, Interview Preparation Tips & Instant Alerts directly on WhatsApp.
π Join WhatsApp Nowπ’ Join Our Telegram Channel
πΌ Get Daily IT Job Updates, Interview Tips & Exclusive Alerts directly on Telegram!
π Join Telegram