继承中的成员方法

xiaoxiao2021-02-27  805

继承中成员方法关系 * a:不同名的方法 * b:同名的方法(就近原则)

public class exdemon { public static void main(String[] args) { Son s = new Son(); s.print(); s.method(); } } class Father { public void print() { System.out.println("Fu print"); } } class Son extends Father { public void method() { System.out.println("Zi Method"); } //子类与父类的方法名相同时也叫做重写或覆盖 public void print() { //super.print(); //super可以调用父类的成员方法,注意与构造方法的区别 System.out.println("Zi print"); } }

转载请注明原文地址: https://www.6miu.com/read-447.html

最新回复(0)