1.public class DieThreadDemo {
public static void main(String[] args) {
Example example=new Example();
helloThread1 thread1=new helloThread1(example);
thread1.start();
helloThread2 thread2=new helloThread2(example);
thread2.start();
}
}
class helloThread1 extends Thread{
private Example example=null;
public helloThread1(Example example){
this.example=example;
}
@Override
public void run() {
example.method1();
}
}
2.public class hello {
public static void main(String[] args) {
helloThread1 thread1=new helloThread1();
thread1.start();
helloThread2 thread2=new helloThread2();
thread2.start();
}
}
class helloThread1 extends Thread{
Example example=new Example();
public void run(){
example.method1();
}
}风一般的男人
相关分类