class Testextends extends Thread
{
private int x=10;
public void run()
{
while(x>0)
{
System.out.println(Thread.currentThread().getName()+" extends: "+x--);
}
}
}
class Testimplemets implements Runnable
{
private int y=10;
public void run()
{
while(y>0)
{
System.out.println(Thread.currentThread().getName()+" implements : "+y--);
}
}
}
class test
{
public static void main(String[] argv)
{
Testextends e1 = new Testextends();
Testextends e2 = new Testextends();
e1.start();
e2.start();
Testimplemets i = new Testimplemets();
Thread t1 = new Thread(i);
Thread t2 = new Thread(i);
t1.start();
t2.start();
}
}
继承方式里面的成员变量x不是共享的,实现方式里面的成员变量y是共享的,想问下他们内存分布是怎么下的 求解答,谢谢 |
|