OOP(object-oriented programming)
OOP core = Encapsulation + Inheritance + Polymorphism1. Encapsulation封装
Hide internal details, expose only what’s needed.
classUser {
privateStringname;
publicStringgetName() {
returnname;
}
}2. Inheritance继承
Reuse and extend behavior.
classAnimal {}
classDogextendsAnimal {}3. Polymorphism多态
Same interface, different behavior.
Animala=newDog();