ylsunyuan技术论坛
标题:
thist 和 super 关键字的用法
[打印本页]
作者:
sun
时间:
2015-11-24 20:09
标题:
thist 和 super 关键字的用法
public class ThisSuper {
public static void main(String[] args){
Son bb = new Son();
bb.showAge();
}
}
class Father{
public int age = 58;
}
class Son extends Father{
public int age = 24;
public void showAge(){
int age = 12;
//直接输出 输出最近的一个AGE变量 就近原则
System.out.println(age);
//通过this关键字 输出本类中的 AGE 属性
System.out.println(this.age);
//通过super关键字 输出父类中的 AGE 属性
System.out.println(super.age);
}
}
复制代码
欢迎光临 ylsunyuan技术论坛 (http://bbs.ylsunyuan.com/)
Powered by Discuz! X3.2