class ThreadTest extends Thread{
Thread t;
public ThreadTest(){
t=new Thread(this);
}
}为什么要加这个 this对象 呢??? 我明白this 是返回引用这个方法的自身对象,但用这里有什么意思
Thread t;
public ThreadTest(){
t=new Thread(this);
}
}为什么要加这个 this对象 呢??? 我明白this 是返回引用这个方法的自身对象,但用这里有什么意思
class Son extends Thread {
Thread t;
public Son(){
t = new Thread(this);
}
public void run(){
Conica.pl("i love this thread.");
}
public static void main(String[] args){
Son son = new Son();
son.t.start();
}
}楼主可以观察,这段程序的输出是:i love this thread.
若t = new Thread()的话,
则没有任何输出。
创建本类一个线程: qq14923349(剑神) 正确
Thread t;
private static int i = 0;
public ThreadTest(){
t = new Thread(this);
t.run();
}
public void run() {
System.out.println(i++);
}
public static void main(String[] args) {
new ThreadTest();
new ThreadTest();
}
}
System.out.println(i++);
} public static void main(String[] args) {
new ThreadTest().start();
new ThreadTest().start();
}
}
Thread t;
private int i = 0;
public Son(){
t = new Thread(this);
t.run();
}
public void run() {
System.out.println(i++);
}
public static void main(String[] args) {
Son a=new Son();
Son b=new Son();
a.start();
b.start();
}
}
请问这个的输出是多少?哪位能给我讲一下STATIC的作用和用法?