當前位置:編程學習大全網 - 網站源碼 - JAVA中子類繼承父類,父類中有this方法this方法返回誰的引用

JAVA中子類繼承父類,父類中有this方法this方法返回誰的引用

根據妳的提問我把程序改了壹下,去掉了壹些與妳提問無關的東西,加了壹些我想要做的

源代碼:

public class F

{

int a;

F()

{

System.out.println("fsdlkfjlsdk");

this.getA();

a=33;

System.out.println("fsdlkfjlsdk"+a);

}

void getA()

{

System.out.println("fsdlkfj");

System.out.println("father"+"\n"+"class"+a);

}

public static void main(String[] args)

{

F f=new F();

C c=new C();

c.getA();//多加的部分

}

}

class C extends F

{

int a;

C()

{

a=1;

}

void getA()

{

System.out.println("wo zai sub class nie");

System.out.println("subclass"+a);

}

}

試著運行程序並理解之。妳就會找到想要的。壹定要靜下心來。

提示:要考慮到子類對父類的重寫,註意覆蓋,也不要太死板。不要僅僅記得妳所學的,

還要記得妳所看到的!

  • 上一篇:手機相冊裏的照片都被刪了。怎麽做才能恢復手機照片?
  • 下一篇:易語言的IP地址怎麽弄 例如:廣東省.廣州市.電信
  • copyright 2024編程學習大全網