Polymorphism

🔁 Polymorphism Polymorphism allows one interface to be used for different underlying forms (data types). It enables the same method name to behave differently depending on the context — improving flexibility and maintainability. 🎯 Types of Polymorphism in Java Compile-time (Static) Polymorphism Achieved via method overloading — same method name with different parameters. Runtime (Dynamic) Polymorphism Achieved via method overriding — subclass provides a specific implementation of a method defined in its superclass. ...

May 8, 2025 · 1 min · Rohan

Encapsulation

🔐 Encapsulation Encapsulation is one of the four core principles of Object-Oriented Programming. It involves wrapping data and code that operates on the data into a single unit: the class. 🧩 Key Concepts Declaring variables as private to prevent direct access from outside. Providing public methods (getters/setters) to read or modify private variables. Helps enforce data protection, validation, and clean APIs. 📌 Why Use Encapsulation? Keeps internal implementation hidden Prevents external interference or misuse Allows safe and controlled access Promotes modularity and maintainability 🧪 Java Example class Student { private int age; // Setter with validation public void setAge(int a) { if (a > 0) age = a; } // Getter public int getAge() { return age; } } 🔗 Related Notes History and Evolution OOPs Principles Features of Java Inheritance Polymorphism Abstraction

May 8, 2025 · 1 min · Rohan