click below
click below
Normal Size Small Size show me how
OOP - L1
Encapsulation, Inheritance, Polymorphism
| Question | Answer |
|---|---|
| What is OOP? | Object Oriented Programming |
| The name of the class whose object you want to create. | ClassName |
| A reference variable that will point to the object. | objectName |
| Keyword used to allocate memory for the object | new |
| - Calls the constructor of the class (parameters are optional depending on the constructor). | ClassName (parameters) |
| is the principle of pushing data (fields) and methods that operate on that data into a single unit (class), while restricting direct access to the data by using access modifiers | Encapsulation |
| Wrapping variables (data) and methods (code) together in one class | Encapsulation |
| Protects data integrity by controlling how values are set | Encapsulation |
| is an Object-Oriented Programming (OOP) concept where one class (child/subclass) acquires the properties and behaviors of another class (parent/superclass) using the extends keyword. | Inheritance |
| The class whose features are inherited. | Superclass (Parent/Base Class): |
| The class that inherits from the superclass. | Subclass (Child/Derived Class) |
| extends is used to establish inheritance. | Keyword: |
| Subclass can reuse fields and methods of the parent class. | Reusability |
| Subclass can add new fields/methods or override existing ones | Customization |
| Enables writing flexible code where a parent reference can point to child objects. | Polymorphism |
| Types of Inheritance | Single Inheritance Multilevel Inheritance Hierarchical Inheritance Hybrid Inheritance |
| One class inherits from another | Single Inheritance |
| A class inherits from a subclass (chain). | Multilevel Inheritance |
| Multiple classes inherit from one superclass. | Hierarchical Inheritance |
| Combination of different types (not directly supported in Java due to ambiguity, but achievable via interfaces) | Hybrid Inheritance |
| means “many forms” — it allows the same method or object to behave differently depending on the context, typically through method overloading (compile-time polymorphism) and method overriding (runtime polymorphism). | Polymorphism |
| Multiple methods with the same name but different parameter lists. | Compile-time polymorphism |
| A subclass provides a specific implementation of a method already defined in its superclass. | Runtime polymorphism |
| Types of Polymorphism | Types of Polymorphism |
| Achieved by function overloading or operator overloading | Compile-time Polymorphism |
| Why Encapsulation Matters? | Security Flexibility Validation Reusability |