方法重载

  方法重载 :方法名相同,参数列表不同(个数,顺序,类型只要有一个不同);


//写方法计算数间的求和 public static int get(int a,int b ){ return a+b; } public static double get(int a,double b ){ return a+b; } public static double get(double a,int b ){ return a+b; } public static double get(double a,double b,double c){ return a+b+c; }

方法重写:1.方法的返回值类型 方法名 参数列表都要一样

2.子类方法覆盖父类方法,必须要保证权限大于等于父类权限。



class
Fu { public void show() { System.out.println("Fu show"); } } class Zi extends Fu { //子类重写了父类的show方法 public void show() { System.out.println("Zi show"); } }
原文地址:https://www.cnblogs.com/longmingyeyu/p/12533062.html