The four OOP pillars
Encapsulation hides state behind public methods. Inheritance reuses and extends classes. Polymorphism lets subclasses share an interface. Abstraction hides complexity behind simple interfaces like interfaces and abstract classes.
Method overriding and polymorphism
A subclass can override a parent method:
class Animal {
void sound() { System.out.println("..."); }
}
class Dog extends Animal {
@Override
void sound() { System.out.println("woof"); }
}
Animal a = new Dog(); // polymorphic reference
a.sound(); // woof (runs Dog's version)
The declared type is Animal, but the runtime type is Dog, so the overridden method runs. Java binds these calls dynamically.