发布网友 发布时间:2022-04-23 01:55
共1个回答
热心网友 时间:2023-10-10 19:59
public class ThreadA{
private Integer num ;
public ThreadA (Integer num ){
this.num=num
Threadb test = new Threadb(num);
}
public static void main(String args[]){
Integer num =1;
ThreadA test = new ThreadA(num);
System.out.println(test.num);
}
}
//第二个线程类
class Threadb extends Thread{
private Integer num ;
public Threadb(Integer num ){
this.num = num;
}
public void run(){
while(true){
num=10000;
}
}
}
这样试试,对象都是按引用传值。你的变成习惯需要改进,构造函数用于初始化数据比较好,test.num=10这样不是很安全