//System.out.println("Hello World!");
Pig pig1 = new Pig();
pig1.test();
int result = pig1.add(1,2);
System.out.println(result);
int result2 = pig1.add(1,2,3);
System.out.println(result2);
int result3 = pig1.add(1,2,'a');
System.out.println(result3);
double result4 = pig1.add(1,2,23.5);
System.out.println(result4);
}
}
class Pig
{
public void test(){// void表示没有返回值
System.out.println("haoren");
}
//方法重载,方法名和其他的都相同,只有参数的个数和类型不同。
public int add(int num1,int num2){
return num1+num2;
}
public int add(int num1,int num2, int num3){
return num1+num2+num3;
}
public int add(int num1,int num2, char num3){
return num1+num2+num3;
}
public double add(int num1,int num2, double num3){
return num1+num2+num3;
}