0% found this document useful (0 votes)
2 views6 pages

Oops

The document provides an overview of Object-Oriented Programming (OOP), detailing its fundamental concepts such as encapsulation, abstraction, inheritance, and polymorphism. It explains key terms like classes, objects, constructors, destructors, and access specifiers, along with advanced concepts like composition, coupling, and design patterns. Additionally, it highlights the importance of SOLID principles for writing maintainable OOP code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Oops

The document provides an overview of Object-Oriented Programming (OOP), detailing its fundamental concepts such as encapsulation, abstraction, inheritance, and polymorphism. It explains key terms like classes, objects, constructors, destructors, and access specifiers, along with advanced concepts like composition, coupling, and design patterns. Additionally, it highlights the importance of SOLID principles for writing maintainable OOP code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1. What is Object-Oriented Programming (OOP)?


Answer: OOP is a programming paradigm based on the concept of "objects", which can
contain data (fields) and code (methods). It promotes code reusability, scalability, and
maintainability.

2. What are the four pillars of OOP?​


Answer:

●​ Encapsulation – Wrapping data and methods into a single unit (class).​

●​ Abstraction – Hiding internal details and showing only essential features.​

●​ Inheritance – Acquiring properties and behaviors from a parent class.​

●​ Polymorphism – Performing a task in different ways (method


overloading/overriding).​

3. What is a Class and an Object?​


Answer:

●​ Class: A blueprint or template to create objects.​

●​ Object: An instance of a class with real values.​

4. What is Encapsulation?​
Answer: Binding data and methods together and restricting direct access using access
modifiers (e.g., private, public).

5. What is Abstraction?​
Answer: Showing only relevant details to the user and hiding the internal implementation.
It’s achieved using abstract classes and interfaces.

6. What is Inheritance?​
Answer: The process by which one class acquires the properties and methods of another.

●​ Promotes reusability.​
●​ Helps in hierarchical classification.​

7. What is Polymorphism?​
Answer: The ability to take many forms.

●​ Compile-time (Method Overloading)​

●​ Run-time (Method Overriding)​

8. What is Method Overloading?​


Answer: Having multiple methods with the same name but different parameters in the same
class (compile-time polymorphism).

9. What is Method Overriding?​


Answer: Redefining a parent class method in the child class with the same signature
(runtime polymorphism).

10. What is a Constructor?​


Answer: A special method used to initialize objects. It has the same name as the class and
no return type.

11. What is a Destructor?​


Answer: A method called automatically when an object is destroyed (mainly in C++). In
Java, garbage collection handles this.

12. What is the difference between Abstraction and Encapsulation?​


Answer:

●​ Abstraction hides implementation.​

●​ Encapsulation hides data.​


Abstraction is about what, and encapsulation is about how.​
13. What are access specifiers/modifiers?​
Answer: They define the scope/visibility of class members.

●​ public: Accessible everywhere.​

●​ private: Accessible within the class only.​

●​ protected: Accessible within package and subclasses.​

●​ default: Package-level access.​

14. What is the difference between Class and Object?​


Answer:

●​ Class is a logical structure (definition).​

●​ Object is a real instance of the class (allocated in memory).​

15. Can we overload constructors?​


Answer: Yes, by defining constructors with different parameter lists.

🔹 Intermediate Concepts
16. What is an Abstract Class?​
Answer: A class that cannot be instantiated and may contain abstract methods (without
implementation). Used for partial abstraction.

17. What is an Interface?​


Answer: A reference type in Java/C++ that can only have abstract methods (till Java 7).
Used for full abstraction.

18. Difference between Abstract Class and Interface?

Feature Abstract Class Interface

Inheritance type Single Multiple


Implementation Can have Only method signatures (until Java
methods 8)

Use Partial abstraction Full abstraction

19. What is multiple inheritance? Is it supported in Java?​


Answer: Multiple inheritance means a class inherits from more than one class.

●​ Java supports multiple inheritance using interfaces, not classes (to avoid ambiguity).​

20. What is the ‘super’ keyword?​


Answer: Used to refer to the immediate parent class’s method or constructor.

21. What is ‘this’ keyword?​


Answer: Refers to the current instance of the class.

22. What is a static method?​


Answer: A method that belongs to the class, not to instances. It can be called without
creating an object.

23. Can static methods be overridden?​


Answer: No. Static methods belong to the class and not instances, so they cannot be
overridden but can be hidden.

24. What is final keyword in OOP?​


Answer:

●​ final class: Cannot be extended.​

●​ final method: Cannot be overridden.​

●​ final variable: Acts as a constant.​


25. What is object cloning?​
Answer: Creating an exact copy of an object using clone() method (Java). The class
must implement Cloneable.

🔹 Advanced OOP Concepts


26. What is composition?​
Answer: When a class contains references to other classes as part of its fields. Represents
a “has-a” relationship.

27. Difference between Association, Aggregation, and Composition?

●​ Association: General relationship (e.g., Teacher teaches Student)​

●​ Aggregation: Weak "has-a" relationship (objects can exist independently)​

●​ Composition: Strong "has-a" relationship (objects cannot exist independently)​

28. What is dynamic method dispatch?​


Answer: Runtime polymorphism in which the method call is resolved at runtime based on
object type.

29. What is early and late binding?​


Answer:

●​ Early Binding: Compile-time method resolution (e.g., method overloading)​

●​ Late Binding: Runtime method resolution (e.g., method overriding)​

30. Can we create an object of abstract class or interface?​


Answer: No, they can only be extended (abstract class) or implemented (interface).

31. What is coupling in OOP?​


Answer: The degree to which one class depends on another.
●​ Low coupling is preferred for better modularity.​

32. What is cohesion in OOP?​


Answer: How closely the responsibilities of a class are related.

●​ High cohesion is desirable.​

33. What is SOLID in OOP?​


Answer: Design principles for writing clean and maintainable OOP code:

●​ S: Single Responsibility​

●​ O: Open/Closed​

●​ L: Liskov Substitution​

●​ I: Interface Segregation​

●​ D: Dependency Inversion​

34. What is the difference between shallow and deep copy?​


Answer:

●​ Shallow Copy: Copies object reference.​

●​ Deep Copy: Copies all fields and nested objects recursively.​

35. What are design patterns in OOP?​


Answer: Best practices used to solve common software design problems (e.g., Singleton,
Factory, Observer).

You might also like