Understanding OOP -Inheritance, Polymorphism, Encapsulation
1. Quick Recap: What is OOP? OOP (Object-Oriented Programming) is about designing programs around objects that have data (attributes) and behaviors (methods) . Main OOP principles: Inheritance – Reuse code from one class in another Polymorphism – One method, many forms Encapsulation – Protect data by controlling access Abstraction – Hide implementation details (covered later) 2. Access Modifiers in Java Access modifiers control visibility of classes, methods, and variables. Modifier Access Level public Accessible from anywhere protected Accessible in same package and subclasses default (no keyword) Accessible in same package only private Accessible only inside the same class 3. Inheritance – Reusing Code Inheritance allows one class ( child/subclass ) to get properties and methods from another class ( parent/superclass ). Example: class Vehicle { public void start () { System.out.println( "Vehicle is starting..." ); } } ...