package com
.lzy
.thread
;
public class aStartThread extends Thread{
@Override
public void run() {
for(int i
=0;i
<20;i
++) {
System
.out
.println("一边studying");
}
}
public static void main(String
[] args
) {
aStartThread st
=new aStartThread();
st
.start();
for(int i
=0;i
<20;i
++) {
System
.out
.println("一边play");
}
}
}
15行run()方法为线程入口点,如果在main()方法中直接调用run()方法而不是用start()方法,则不会发生多线程,运行后“一边studying”执行完才会执行“一边play”。或者将26 27行放到22行上面,运行后”一边play“执行完才会执行“一边studying”。
转载请注明原文地址:https://blackberry.8miu.com/read-29702.html