码迷,mamicode.com
首页 > 其他好文 > 详细

super的理解

时间:2016-03-02 00:03:35      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

super关键词
1访问父类被隐藏的属性
public class Parent(){
int money=10000;
}
public class Child extends Parent(){
int money=100;
pulbic int getParentMoney(){
return super.money
}
}
2访问父类的方法
public class Parent{
pulbic void run(){}
}

public class Child extends Parent{
@override
public void run(){
super.run();
//todo
}
}

3,访问父类的构造方法
public class Parent extends Object{
public Parent(){
super();
}
}
当调用父类的构造方法时,需:
*在子类中调用直接父类的构造方法
*调用父类构造方法的语句,必须是子类的构造方法中第一行有效代码

public class Test{
public int x;
‘public static void test(){
System.out.println(this.x);
}
}

super的理解

标签:

原文地址:http://www.cnblogs.com/gentspy/p/5233197.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!