What are the four main principles of Object-Oriented Programming (OOP)?
Abstraction, Encapsulation, Inheritance, and Polymorphism.
What is abstraction in OOP?
Abstraction hides implementation details and exposes only essential features through interfaces or abstract classes.
Why is abstraction important?
It reduces complexity and allows developers to focus on what an object does instead of how it does it.
What is encapsulation in OOP?
Encapsulation bundles data and methods together and restricts direct access to internal state using access modifiers.
Why is encapsulation useful?
It protects data integrity and prevents unintended modification from outside code.
What is inheritance in OOP?
Inheritance allows one class to acquire properties and methods of another class using extends.
Why use inheritance?
It promotes code reuse and establishes hierarchical relationships between classes.
What is polymorphism in OOP?
Polymorphism allows objects to behave differently depending on context, typically via method overriding or overloading.
What are the two main types of polymorphism?
Compile-time polymorphism (method overloading) and runtime polymorphism (method overriding).
What is runtime polymorphism?
It occurs when a superclass reference points to a subclass object and the method executed is determined at runtime.
What is the difference between abstraction and encapsulation?
Abstraction hides complexity of implementation, while encapsulation hides internal state and protects data.
Which OOP principle supports code reuse most directly?
Inheritance.
Which OOP principle improves security and data protection?
Encapsulation.
Which OOP principle enables flexibility and extensibility?
Polymorphism.
Real-world example of OOP principles working together?
A Payment class hierarchy where abstraction defines payment methods, encapsulation protects transaction data, inheritance creates subclasses like CreditCardPayment, and polymorphism allows different payment processing behaviors.
What is the difference between Object-Oriented and Object-Based programming languages?
Object-Oriented languages support all OOP principles including inheritance and polymorphism, while Object-Based languages support objects and encapsulation but typically lack inheritance and runtime polymorphism.
What defines an Object-Oriented Programming language?
A language that supports abstraction, encapsulation, inheritance, and polymorphism as core features.
What defines an Object-Based Programming language?
A language that supports objects and encapsulation but usually does not support inheritance or true polymorphism.
Give examples of Object-Oriented languages.
Java, C++, C#, Python.
Give examples of Object-Based languages.
JavaScript (traditionally classified), VBScript, and some scripting languages.
Do Object-Based languages support inheritance?
Traditionally no class-based inheritance, though some support prototype-based reuse.
What is prototype-based programming?
A style where objects inherit directly from other objects instead of classes.
Is JavaScript purely Object-Based?
Historically yes, but modern JavaScript supports class syntax and inheritance, making it multi-paradigm.