1. Associating a method call with a method body is called
2. Compile-time binding (static) is the type of reference object that was determined during the program compilation phase
3. Run-time binding (dynamic binding) is the actual type of the referenced object that is judged during execution, and its corresponding method is called according to its actual type
4. In addition to the static method and the final method (the private method belongs to the final method), all other methods are late-bound, and all methods in Java are dynamically bound to implement polymorphic
5. The behavior of accessing a domain is not polymorphic
Package Polymorphism;class Superfield {public int field = 1;public int GetField () {return field;}} Class SubField extends Superfield {public int field = 2;public int GetField () {return field;} public int Getsuperfield () {return super.field;}} public class Fieldpolymorphism {public static void main (string[] args) {superfield sup = new SubField (); System.out.println ("Sup.field =" + Sup.field + ", sup.getfield () =" + Sup.getfield ()); SubField sub = new SubField (); System.out.println ("Sub.field =" + Sub.field + ", sub.getfield () =" + Sub.getfield () + ", sub.getsuperfield () =" + SUB.G Etsuperfield ());}}
Output Result:
Sup.field = 1, Sup.getfield () = 2
Sub.field = 2, Sub.getfield () = 2, Sub.getsuperfield () = 1
When the subfield object is transformed into a super reference, any domain access operations will be parsed by the compiler, so it is not polymorphic, and subfield actually contains two fields called field: their own and inherited from the Superfield.
The domain is usually set to private, cannot be accessed directly, and cannot be inherited by invoking methods to access
6. Access to a static method is not polymorphic and is not associated with a single object
Package Polymorphism;class Super {public static String Staticmethod () {return "Super Staticmethod ()";}} Class Sub extends Super {public static String Staticmethod () {return "Sub Staticmethod ()";}} public class Staticpolymorphism {public static void main (string[] args) {Super sup = new Sub (); System.out.println (Sup.staticmethod ()); System.out.println (Sub.staticmethod ());}}
Output Result:
Super Staticmethod ()
Sub Staticmethod ()
Access to domain and static methods in Java is not polymorphic