(1) Domain and static methods
Remember that " only normal method calls are Polymorphic ".
The domain and static methods are not: Access to the domain has been parsed and bound during compilation. And if a method is static, there is no polymorphism.
(2) Writing a constructor has a guideline:
* Use the simplest possible method to get the object into a normal state and try to avoid calling other methods.
* methods that can be safely called within the constructor are only those final methods (private default final), because they can't be overwritten.
(3) polymorphic concept:
Polymorphism refers to the coexistence of different methods with the same name in a program.
These methods have the same name because their final function and purpose are the same, but because they may encounter different situations when they complete the same function, it is necessary to define a method with different specific content to represent a variety of concrete implementation forms.
(4) Java provides two polymorphic mechanisms: overloading and rewriting.
The overridden overriding and overloaded overloading of a method are different manifestations of Java polymorphism.
Overriding overriding is a representation of polymorphism between a parent class and a subclass, and overloading overloading is a representation of polymorphism in a class.
= " If you define a method in a subclass that has the same name and parameters as its parent, we say that the method is overridden (overriding). when an object of a subclass uses this method, the definition in the subclass is called, and for it the definition in the parent class is "masked".
= " if more than one method with the same name is defined in a class, they either have a different number of arguments or have different parameter types, it is called a method overload (overloading). the overloaded method is to change the type of the return value (that is, only the return value is not overloaded). Instead , the parameter names are the same, as long as the types are overloaded, even if they are inherited from each other.
Java Basics: Polymorphism (overloading and rewriting)