Concept Flow - OOP principles overview
Start
Encapsulation
Inheritance
Polymorphism
Abstraction
End
This flow shows the four main OOP principles in order: Encapsulation, Inheritance, Polymorphism, and Abstraction.
class Animal { void sound() { System.out.println("Some sound"); } } class Dog extends Animal { void sound() { System.out.println("Bark"); } } public class Main { public static void main(String[] args) { Animal a = new Dog(); a.sound(); } }
| Step | Action | Object Type | Method Called | Output |
|---|---|---|---|---|
| 1 | Create Dog object assigned to Animal reference | Dog | none | none |
| 2 | Call sound() on Animal reference | Dog | sound() | Bark |
| 3 | End of main method | none | none | none |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| a | null | Dog object reference | Dog object reference | Dog object reference |
OOP Principles in Java: - Encapsulation: Hide data inside classes - Inheritance: Child classes reuse parent code - Polymorphism: Same method acts differently - Abstraction: Show only needed details Use classes and methods to organize code clearly.