ylsunyuan技术论坛

标题: thist 和 super 关键字的用法 [打印本页]

作者: sun    时间: 2015-11-24 20:09
标题: thist 和 super 关键字的用法
  1. public class ThisSuper {
  2.         public static void main(String[] args){
  3.                
  4.                 Son bb = new Son();
  5.                
  6.                 bb.showAge();
  7.         }
  8. }


  9. class Father{
  10.         public int age = 58;
  11. }

  12. class Son extends Father{
  13.         public int age = 24;
  14.        
  15.        
  16.         public void showAge(){
  17.                 int age = 12;
  18.                 //直接输出  输出最近的一个AGE变量  就近原则
  19.                 System.out.println(age);
  20.                 //通过this关键字   输出本类中的  AGE 属性
  21.                 System.out.println(this.age);
  22.                 //通过super关键字   输出父类中的  AGE 属性
  23.                 System.out.println(super.age);
  24.         }
  25. }
复制代码







欢迎光临 ylsunyuan技术论坛 (http://bbs.ylsunyuan.com/) Powered by Discuz! X3.2