"Java Programming Thought" Notes Chapter 8 Polymorphism

1. Upward Transformation

  •  Treat subclass references as superclass references. (Subclass object is assigned to parent class reference)

2. Binding

  • Determine which class the method belongs to.

3. Early binding

  •  Bind before program execution.

4. Late binding is also called dynamic binding

  •  Program runtime binding.

5. Constructors and Polymorphism

5.1 Fields and static methods (including constructors) are not polymorphic.

5.2  The constructor can be polymorphic, calling the overridden method in the subclass, but it is not safe .

5.3 The only methods that can be safely called in the constructor are the final methods of the base class.

Knowledge point

  • After the private method is overwritten, it has nothing to do with the base class. The new method belonging to the subclass has the same name as the private method of the base class.
  • The order of cleanup and initialization is reversed .
  • this represents a reference to this object.
  • Except for final static private methods, all other methods are dynamically bound.
  • Compile Java files are compiled into class files, each class is a class file, including inner classes. The first time you use the code, the class file is loaded , and the class file is loaded only once .


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325392249&siteId=291194637