代码改变世界

随笔档案-2011年11月

this/super

2011-11-09 11:02 by ...平..淡..., 189 阅读, 收藏,
摘要: java中,this用来指向或调用当前类的数据和方法,super用来调用父类的数据和方法。以下程序中通过对构造函数的调用来说明一些问题:1.在子类的一个构造函数中,不论this调用当前类的其他构造函数、或是super调用父类构造函数,都是放在子类的第一句,两者不能同时使用。2.如代码中注释所示this/super 1 public class test 2 { 3 public static void main(String[] args) 4 { 5 new B(); 6 } 7 } 8 9 10 class A{11 A(){12 ... 阅读全文