/*
this 和super的區(qū)別:
this: 代表本類對應(yīng)的引用
super:代表父類存儲空間的標識(可以理解為父類的引用,可以操作父類的成員)
怎么用:
A:調(diào)用成員變量:
this.成員變量:調(diào)用本類的成員變量
super.成員變量:調(diào)用父類的成員變量
B:調(diào)用構(gòu)造方法:
this(...) 調(diào)用本類的構(gòu)造方法
super(...)調(diào)用父類的構(gòu)造方法
C:調(diào)用成員方法
this.成員方法:調(diào)用本類的成員方法
super.成員方法:調(diào)用父類的成員方法
*/
==============================練習A================================
class Card{
public int num =10;
}
class Car extends Card{
private int num1 = 20;
public int num =30;
public void show(){
int num = 40;
System.out.println(num);
System.out.println(num1);
System.out.println("本類"+this.num);
System.out.println("父類"+super.num);
}
}
class CardDemo{
public static void main(String [] args){
Car c =new Car();
c.show();
}
}
結(jié)果:
40
20
本類30
父類10
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報。