这个程序是网上找到的,看不太懂。编译之后有几个错误,我不知道怎么改。
public class A
{
int i = 1;
public A()
{
Thread thread = new Thread();
public void run()
{
for(;;)
{
A.this.run();
try
{
sleep(1000);
}
catch(InterruptedException ie)
{
}
}
}
thread.start();
}
public void run()
{
System.out.println("i = " + i);
i++;
}
public static void main(String[] args) throws Exception
{
new A();
}
}
public class A
{
int i = 1;
public A()
{
Thread thread = new Thread();
public void run()
{
for(;;)
{
A.this.run();
try
{
sleep(1000);
}
catch(InterruptedException ie)
{
}
}
}
thread.start();
}
public void run()
{
System.out.println("i = " + i);
i++;
}
public static void main(String[] args) throws Exception
{
new A();
}
}
public class A { int i = 1; public A() {
Thread thread = new Thread() {
public void run() {
for (;;) {
A.this.run();
try {
sleep(1000);
} catch (InterruptedException ie) {
}
}
}
};
thread.start();
} public void run() {
System.out.println("i = " + i);
i++;
} public static void main(String[] args) throws Exception {
new A();
}
}
回去看看java线程。
这里要用到匿名内部类