java论坛进不去,来这问下吧
class SuperClass{
int x;
SuperClass()
{
x = 3;
System.out.println("in SuperClass: x = " + x);
}
void doSomething()
{
System.out.println("in SuperClass.doSomething()");
}
}
class SubClass extends SuperClass
{
int x;
SubClass()
{
super();
x = 5;
System.out.println("in SubClass : x = " + x);
}
// @Override
void doSometing()
{
super.doSomething();
System.out.println("in SubClass.doSomething()");
System.out.println("super.x = " + super.x + "sub.x = " + x);
}
}
public class VariableTest
{
public static void main(String args[])
{
SubClass subC=new SubClass();
subC.doSomething();
B b = new B();
b.callme();
}
}
class A
{
void callme()
{
System.out.println("A");
}
}
class B extends A
{
void callme()
{
System.out.println("B");
}
}
为什么输出结果会是
in SuperClass: x = 3
in SubClass : x = 5
in SuperClass.doSomething()
B
就是为什么一个调用子类,一个调用父类?淡定,请版主不要删我的贴,实在是没办法啊。。java那边我进不去,说我没权力进去。。。