package Test;

class SuperClass{

int x;

SuperClass()

{

 x=3;

 System.out.println("in supclass:x="+x);

}

void doSomething() {

 System.out.println("in superclass:do something()");

}

}

class SubClass extends SuperClass{

int x;

SubClass()

{

 super();

 x=5;

 System.out.println("in subclass:x="+x);

}

void doSomething() {

 super.doSomething();

 System.out.println("in subclass.dosomething()");

 System.out.println("super.x="+super.x+"sub.x"+x);

}

}

public class Inheritance {

public static void main(String args[])

{

SubClass subC=new SubClass();

subC.doSomething();

}

}




java成员变量隐藏、方法覆盖用super的使用_System