现在的位置: 首页 > 综合 > 正文

java super,this用法

2013年11月26日 ⁄ 综合 ⁄ 共 421字 ⁄ 字号 评论关闭

package xxj.one;

public class Test {
 int x=1;
 
 void eat(){
  System.out.println("father eat");
 }
 
}

 

package xxj.one;

public class TestA extends Test{
 int x=2;
 
 void eat(){
  System.out.println("son eat");
 }
 
 void run(){
  int x=3;
  System.out.println(x);
  System.out.println(this.x);
  System.out.println(super.x);
  super.eat();
  eat();
 }
}

 

package xxj.one;

public class Main {

 public static void main(String[] args) {
  TestA ta = new TestA();
  ta.run();
 }
}

 

 

 

抱歉!评论已关闭.