Only interfaces can do multiple inheritance
extends and implements
• A class can only extend 1 class: – meaning 1 class can only have 1 parent; – a PinkBunnyRabbit can only have one direct parent – Rabbit.
• A class can implement as many interfaces as it likes! – A PinkBunnyRabbit can be (via interfaces) a BigBadies and Teleportable.
接口中的所有东西都是抽象的(public abstract void run(){})
不能在接口中实例化出一个对象
Notes on Abstruct class and interface
Neither abstract classes and interfaces can have an instance made of them.
• If you don’t provide any method implementation, then use an interface instead of an abstract class.
• A class can implement many interfaces, but extends only one superclass.
• Interfaces are how Java provides (a kind of) multiple inheritance.
• If even one method in a class is declared to be abstract, then the whole class must be declared abstract.
• Both abstract classes and interfaces can contain constants, which will be inherited by classes that extend or implement them, respectively.
An interface may have many methods. If a class implements an interface, but only implements some of its methods, then this class becomes an abstract class; it cannot be instantiated.
Like classes, interfaces can be extended as well
Same named methods: • If they have different parameters, then Child interface has both (this is same as overloading). • If they differ by only return type, then error. • If the two methods are identical, only keep one. – Same named constants: we keep both constants. To refer to them, use parent interface name as prefix.
default methods Allow developers to add new functionality to interfaces, without impacting any existing classes that are already implementing the interface. • Can be overridden in the class that implements the interface. • Provide backward compatibility for existing interfaces.
– static methods Allow developers to define utility methods in the interface. • Are similar to default methods, but cannot be overridden in the class that implements the interface.



