super与this关键字

public class Fu {
int num=10;
public void method(){
System.out.println("父类方法");
}
}
------------------------------
public class Zi extends Fu {
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 Demo {
public static void main(String[] args) {
Zi zi=new Zi();
zi.show();
zi.method();
}
}
//结果:
//30
//20
//10
//父类方法
//子类方法
 
 
posted @ 2022-05-17 21:25  开山y  阅读(11)  评论(0编辑  收藏  举报