public class ThreadTest {
public class void main(String[ ] args){
3.//创建Thread类的子类的对象
MyThread m1 = new MyThread1( ) ;
MyThread m2 = new MyThread2( ) ;
4.//调用此对象调用start
m1.start( );
while(i<=10000){
System.out.println("114514");
}
}
}
class MyThread1 extends Thread {
public void run( ){
int i=0;
int count = 0;//定义一个接收的变量
while(i<=1000){
count += i;//进行累加
i++; }
System.out.println( Thread.currentThread( ).getName( ) + ":" + count );
}
}
class MyThread2 extends Thread {
public void run( ){
int i=0;
int count = 0;//定义一个接收的变量
while(i<=1000){
count += i;//进行累加
i++; }
System.out.println( Thread.currentThread( ).getName( ) + ":" + count );
}
}
标签:count,两个,Thread,int,创建,System,class,线程,public From: https://www.cnblogs.com/liujy2233/p/16867594.html