In reading the Java book, see the overloaded and overwrite this paragraph, some do not understand, and then slowly understand. Now write down some of my ideas.
Overloading refers to a method in which a different method name can be used, but the method of execution differs depending on the number of values passed in or the class.
Package czfx;
public class czfx{
public static void Main (String args[]) {
Class_one p=new Class_one ();
P.talk ();
P.talk (2);
(P.talk);
}
}
Class Class_one
{
void Talk () {
SYSTEM.OUT.PRINTLN ("No incoming value!") ");
}
void talk (int i) {
System.out.println ("There is an incoming value" +i+ "!) ");
}
void talk (int i,int j) {
SYSTEM.OUT.PRINTLN ("There are two incoming values" +i+j+ "!) ");
}
}
Operation Result:
Overwriting is when the subclass inherits the parent class, and the method name of the child class and the parent class can be the same, at which point the method in the subclass overrides the method in the parent class. If the method in the parent class is private, the class will not be established.
Package czfx;
public class czfx{
public static void Main (String args[]) {
Class_one p1=new Class_one ();
Class_two p2=new class_two ();
P1.talk ();
P2.talk ();
}
}
Class Class_one
{
void Talk () {
System.out.println ("This is a test!");
}
}
Class Class_two extends Class_one
{
void Talk () {
System.out.println ("This is A test!");
}
}
Operation Result:
Finish
overloading and overriding in Java