Java polymorphism, interface, abstract class awareness, java Polymorphism
1,
Polymorphism: the reference of the parent class points to the subclass object, which has inheritance and rewriting.
Polymorphism: cat is an Animal
Rule: a multi-state object cannot call methods that are not in the parent class.
Definition: Animal cat = new Cat ();
2,
Interface: the class implementation interface implement is also an extremely abstract class and a set of many behaviors of the class.
The interface indicates that cat has the jump Behavior capability.
Rule: the non-static method of a member is automatically public. The method body is not allowed, the return value is allowed, and the parameter is allowed.
The member property is automatically public final static
Methods In the interface must be implemented
Definition: 1) interface public interface DoolFun {
Public static float pi = 3.45f;
Void alert ();
}
2) Implement the interface public class dool implements DoolFun {
@ Override
Void open (){
// TODO Auto-generated method stub
System. out. println ("open box ");
}
}
3,
Abstract class: the class can inherit the abstract class extends, which is a collection of behaviors of the class. The abstract class is just a few special classes.
Abstract classes Express: cat has eat Behavior
Rule: A member method can have a method body and can contain non-Abstract METHODS. abstract methods are the same as methods in interfaces and must be implemented in subclasses without a method body.
Abstract classes can achieve Polymorphism
The abstract member is automatically public.
Definition: 1) abstract class Animals {}
2) inherit from public class Dog extends Animals