public class Chongzai {
private int m,n;
//overloading of constructor methods, using the This keyword to invoke overloaded other constructor methods
Public Chongzai () {
}
Public Chongzai (int m) {
THIS.M = m;
}
Public Chongzai (int m, int n) {
This (m);
This.n=n;
}
public void SayHello () {
System.out.println ("Hello");
}
//This method differs from the number of first method parameters. Parameter numbers are the same, but different locations are overloaded
public void SayHello (String name) {
System.out.println ("Hello," +name);
}
//This method differs from the parameter type of the second method
public void SayHello (char name) {
System.out.println ("Hello," +name);
}
//NOTE: You cannot use parameter names to differentiate methods,
//NOTE: You cannot use the return value of a method to differentiate overloaded methods, and the return value types of overloaded methods can be different
public int max (int x,int y) {
Return x>y?x:y;
}
public int max (int x,short y) {
System.out.println ("OK");
Return x>y?x:y;
}
public double max (int x,byte y) {
return 0;
}
Public double Max (byte Y,int x) {
return 0;
}
public static void Main (String args[]) {
Chongzai test=new Chongzai ();
Test.sayhello ();
Test.sayhello ("JFL");
Test.sayhello (' A ');
System.out.println (Test.max);
Test.max (1,(short) 2);
}
}
Overloading of methods