- public class MyThread implements Runnable {
- @Override
- public void run() {
- // TODO Auto-generated method stub
- //输出1到5的数
- for (int i = 1; i <= 5; i++) {
- System.out.println(i);
- }
- }
- }
- /**
- * MyThread继承Thread类实现多线程
- * @author suixin
- *
- */
- public class MyThread2 extends Thread {
- @Override
- public void run() {
- // TODO Auto-generated method stub
- super.run();
- for (int i = 1; i <= 5; i++) {
- System.out.println(i);
- }
- }
- }
- public class Test {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Thread thread = new Thread(new MyThread()); //创建MyThread对象
- MyThread2 myThread2 = new MyThread2();
- thread.start();
- System.out.println("");
- myThread2.start();
- }
- }
高级特性第四章1
最新推荐文章于 2019-08-17 04:18:39 发布