public class SuperClass {
int num = 10;
public void method(){
System.out.println("父类方法");
}
}
public class SubClass extends SuperClass{
int num = 20;
@Override
public void method(){
super.method();
System.out.println("子类方法");
}
public void show(){
int num = 30;
System.out.println(num);// 30
System.out.println(this.num);// 20
System.out.println(super.num);// 10
}
}
public class Demo01Extends {
public static void main(String[] args) {
SubClass sub = new SubClass();
sub.show();
sub.method();
}
}
内存图
