/ *
In the parent-child class inheritance relationships among objects create a subclass, the members of the rules of access methods:
objects created who, with a priority on who, if not then look up.
Note:
Whether a member or member variables method, if no parent is looking up, never looking down subclass.
Rewrite (Override)
concept: the inheritance among the same method name, parameter list, too.
Rewrite (Override): Like the name of the method, the parameter list [too]. Cover, overwritten.
Overload (Overload): Like the name of the method, the parameter list [different].
Covering methods of rewriting features: create a subclass object, the priority sub-class method.
* /
public class Demo01ExtendsMethod {
public static void main(String[] args) {
Zi zi = new Zi();
zi.methodFu();
zi.methodZi();
// 创建的是new了子类对象,所以优先用子类方法
zi.method();
}
}
public class Fu {
public void methodFu() {
System.out.println("父类方法执行!");
}
public void method() {
System.out.println("父类重名方法执行!");
}
}
public class Zi extends Fu {
public void methodZi() {
System.out.println("子类方法执行!");
}
public void method() {
System.out.println("子类重名方法执行!");
}
}