class Super
{
int i = 0;
public Super(String a)
{
System.out.println("A");
i=1;
}
public Super()
{
System.out.println("B");
i+=2;
}
}
class Demo extends Super
{
int i = 3;
public Demo(String a)
{
System.out.println("C");
i=5;
}
public static void main(String[] args)
{
int i = 4;
Super d = new Demo("A");
System.out.println(d.i);
Demo m = new Demo("B");
System.out.println(m.i);
}
}
这种情况结果是2,5.字母我就不说了。
class Super
{
int i = 0;
public Super(String a)
{
System.out.println("A");
i=1;
}
public Super()
{
System.out.println("B");
i+=2;
}
}
class Demo extends Super
{
//int i = 3;
public Demo(String a)
{
System.out.println("C");
i=5;
}
public static void main(String[] args)
{
int i = 4;
Super d = new Demo("A");
System.out.println(d.i);
Demo m = new Demo("B");
System.out.println(m.i);
}
}
这种情况就变成了5,5.
class Super
{
int i = 0;
public Super(String a)
{
System.out.println("A");
i=1;
}
public Super()
{
System.out.println("B");
//i+=2;
}
}
class Demo extends Super
{
int i = 3;
public Demo(String a)
{
System.out.println("C");
i=5;
}
public static void main(String[] args)
{
int i = 4;
Super d = new Demo("A");
System.out.println(d.i);
Demo m = new Demo("B");
System.out.println(m.i);
}
}
这种情况又变成了0,5.
class Super
{
int i = 0;
public Super(String a)
{
System.out.println("A");
i=1;
}
public Super()
{
System.out.println("B");
i+=2;
}
}
class Demo extends Super
{
//int i = 3;
public Demo(String a)
{
System.out.println("C");
//i=5;
}
public static void main(String[] args)
{
int i = 4;
Super d = new Demo("A");
System.out.println(d.i);
Demo m = new Demo("B");
System.out.println(m.i);
}
}
这种情况又变成了2,2.
一下子弄出了好几种情况。到底内部的运行机制是什么啊?求高手指教啊。
|