1.一般来说,Abstract class
当我们需要强制关闭 Sub-Class
from Super-Class
的某些功能时,需要 An ,让子类可以灵活地添加其他功能。
例如:
Let Car be the Abstract Super-Class, which has 4 Tyres, 1 Steering ,etc...
Now the Sub classes like Santro i10, Maruti-800, Mahindr Bolero etc are Sub classes,
but they need to have 4 Tyres, 1 Steering to be called a car, not they can have a radio
or not as an additional feature.
2. Interface
是在java中引入的,因为没有Multiple Inheritance。
3. Interface
更多的是关于提供一个 role
.
例如:
Let Dog be the Super-Class
.
Wild Dogs and Pet Dogs are Sub-Classes.
Wild Behavior and Pet Behavior are Interfaces
Now as both Wild Dog and Pet Dog are dogs, but with different behavious. Then they must
implement the Wild Behavior or Pet Behavior respectively