项目中遇到一些诡异的情况,就是这个问题引起的
package com.jenson.extend;
public class Parent {
public void printMsg() {
System.out.println("parent");
}
public void printClassMsg() {
System.out.println(this.getClass().getName());
this.printMsg();
}
}
package com.jenson.extend;
public class Child extends Parent {
@Override
public void printMsg() {
super.printMsg();
System.out.println("child add");
}
@Override
public void printClassMsg() {
super.printClassMsg();
}
}
package com.jenson.extend;
public class ExtendTest {
public static void main(String[] args) {
Parent p = new Parent();
p.printClassMsg();
System.out.println("-----------------------");
Child c = new Child();
c.printClassMsg();
}
}
输出
com.jenson.extend.Parent
parent
-----------------------
com.jenson.extend.Child
parent
child add
网友评论