Basic OOPs Interview Questions
1. What is OOPs?
○ Programming based on objects (instances of classes).
○ Encapsulates data and behavior.
○ Focuses on real-world modeling.
2. Why is OOPs needed?
○ Improves code readability and maintainability.
○ Simplifies complex software development.
○ Supports reuse and modularity.
3. Major OOP languages
○ Java, C++, Python, C#, JavaScript.
○ Emphasize class and object usage.
○ Use features like inheritance, polymorphism.
4. Other programming paradigms
○ Imperative: focuses on how (e.g., procedural).
○ Declarative: focuses on what (e.g., SQL).
○ Includes functional and logical paradigms.
5. Structured Programming
○ Uses clear control structures (if, while, for).
○ Encourages modular coding with functions.
○ Basis for most programming styles.
6. Main OOP features
○ Inheritance
○ Encapsulation
○ Polymorphism
○ Abstraction
7. Advantages of OOPs
○ Code reuse through inheritance.
○ Flexibility via polymorphism.
○ Better code organization and maintenance.
8. Why OOPs is popular
○ Matches real-world modeling.
○ Easy maintenance and scalability.
○ Widely supported by modern languages.
Advanced OOPs Interview Questions
9. What is a Class?
○ A blueprint for creating objects.
○ Contains attributes and methods.
○ No memory allocated until object is created.
10. What is an Object?
○ Instance of a class.
○ Has state (data) and behavior (methods).
○ Occupies memory.
11. Encapsulation
○ Bundles data and methods.
○ Hides internal details (data hiding).
○ Promotes modular code.
12. Polymorphism
○ “Many forms” – same interface, different behavior.
○ Types: Compile-time, Run-time.
○ Increases flexibility.
13. Compile-time vs Run-time Polymorphism
○ Compile-time: method overloading.
○ Run-time: method overriding.
○ Overloading resolved by compiler; overriding at runtime.
14. Polymorphism in C++
○ Compile-time: function overloading, templates.
○ Run-time: virtual functions.
○ Supports both types of polymorphism.
15. Inheritance
○ Child class inherits from parent.
○ Promotes code reuse.
○ Establishes relationships.
16. Abstraction
○ Hides implementation details.
○ Shows only necessary features.
○ Achieved using abstract classes and interfaces.
17. Memory usage of a Class
○ Class itself doesn't occupy memory.
○ Memory allocated when objects are created.
○ Only object instances consume memory.
18. Need for object creation
○ Not needed for static methods.
○ Required for non-static members.
○ Depends on usage.
19. Constructor
○ Initializes objects.
○ Has same name as class.
○ Can be overloaded.
20. Types of Constructors
○ Default: no parameters.
○ Parameterized: takes arguments.
○ Copy constructor: clones another object.
21. Copy Constructor
○ Creates a copy of an existing object.
○ Used in deep vs shallow copy scenarios.
○ Helps clone objects safely.
22. Destructor
○ Frees memory/resources.
○ Called automatically during object deletion.
○ Opposite of constructor.
23. Class vs Structure
○ Class: heap memory, supports OOP features.
○ Structure: stack memory, limited OOP support.
○ Class supports abstraction, structure doesn’t.
24. Inheritance Example
○ Vehicle → Car, Bus inherit common features.
○ Avoids code repetition.
○ Uses base and derived classes.
25. Limitations of Inheritance
○ Tightly coupled classes.
○ Complex for large hierarchies.
○ Increases program size.
26. Types of Inheritance
○ Single
○ Multiple
○ Multilevel
○ Hierarchical
○ Hybrid
27. What is a Subclass?
○ Also called derived or child class.
○ Inherits from a superclass.
○ Can override parent behavior.
28. What is a Superclass?
○ Also called base or parent class.
○ Defines general behavior.
○ Used by one or more subclasses.
29. Interface
○ Contains method declarations (no implementations).
○ Implemented by classes.
○ Used for abstraction.
30. Static Polymorphism
○ Resolved at compile-time.
○ Achieved via method/constructor overloading.
○ Faster execution.
31. Dynamic Polymorphism
○ Resolved at runtime.
○ Achieved via method overriding.
○ Increases flexibility.
32. Overloading vs Overriding
○ Overloading: same name, different params, compile-time.
○ Overriding: same name, runtime behavior changes.
○ Used in different contexts.
33. How Abstraction is Accomplished
○ Using abstract classes or interfaces.
○ Hides implementation logic.
○ Focuses on user-level interaction.
34. Abstract Class
○ Can’t be instantiated.
○ Contains abstract (unimplemented) methods.
○ Can include non-abstract methods too.
35. Abstract Class vs Interface
○ Interface: all methods abstract, no implementation.
○ Abstract class: mix of abstract and concrete methods.
○ Interfaces can’t hold state; abstract classes can.
36. Access Specifiers
○ Control visibility (public, private, protected).
○ Help enforce encapsulation.
○ Key to secure and modular design.
37. What is an Exception?
○ Error during program execution.
○ Halts normal flow.
○ Example: divide by zero, null pointer.
38. Exception Handling
○ Catches and manages errors.
○ Uses try-catch blocks.
○ Prevents program crash.
39. Garbage Collection
○ Automatic memory cleanup.
○ Removes unused objects.
○ Prevents memory leaks.
40. Can Java run without OOPs?
○ No, Java is fully OOP.
○ Objects and classes are core.
○ C++ can be non-OOP, but Java can't.
OOPs Coding Output Questions
41. Constructor Order in Multiple Inheritance
○ Base class constructors called first.
○ Order: Left to right.
○ Then derived class constructor.
42. Static Block Execution Order
○ Static blocks execute before main().
○ Class static block runs on first access.
○ Output order reflects this logic.
43. Type Conversion between Classes
○ Conversion constructors allow implicit conversion.
○ Operators can be overloaded.
○ Enables passing objects where others expected.
44. Main Method Overloading in Java
○ Only main with String[] is valid entry point.
○ Other overloads ignored.
○ JVM follows specific signature.
45. Size with Multiple Inheritance
○ Two copies of base class = more memory.
○ Size increases.
○ Can be optimized with virtual inheritance.
46. Method Resolution in Multi-level Inheritance
○ Closest method is called.
○ Linear search in class hierarchy.
○ Overrides base class version.