The 10th Chapter Polymorphic
This chapter focuses on:
1. polymorphic
2. Dynamic binding and static binding
3. Super class
Polymorphism means having many forms.
In the Java language, polymorphism is mainly about having the same form, but different parameters implement different functions.
Polymorphic Rules:
1, the method name must be the same.
2, incoming parameter type must be the same.
Public class student{
int x;
int y;
int z;
void print (int x) {
SYSTEM.OUT.PRINTLN (2 * x);
}
void Print (int x, int y) {
SYSTEM.OUT.PRINTLN (2 * x + y);
}
Public static void Main (string[] args) {
Student st = new Student ();
St.print (2);
St.print (2, 3);
}
}
Inheritance and polymorphism:
public class studenta{
void print () {
system.out.println ("This is a method");
}
public static void Main (string[] args) {
studenta sta = new Studenta ();
studentb STB = new Studentb ();
sta.print ();
stb.print ();
}
}
Class Studentb extends studentap{
void print () {
System.out.println ("This is a subclass");
}
}
The so-called binding is the binding of the object handle to the method.
Bindings are divided into static bindings and dynamic bindings.
There is no polymorphic problem with static bindings.
There is a polymorphic problem with dynamic binding.
Use of the Equals method:
1, the reflexive nature.
2, symmetry.
3, transmission.
4, consistency.
Overloading: A method that has the same name but different parameters in a class.
Polymorphism: Avoid overloading in the parent class, which causes the code to be bloated and difficult to maintain.
Two forms of polymorphism: overloading and covering.
The 10th Chapter Polymorphic