線程練習2-8
package sample; public class ThreadExercise { class Cat implements Runnable{ @Override public void run() { for (int i = 0; i < 3; i++) { System.out.println(Thread.currentThread().getName() + "A cat"); } } } class Dog implements Runnable{ @Override public void run() { for (int i = 0; i < 3; i++) { System.out.println(Thread.currentThread().getName() + "- A dog"); } } } public void start(){ Cat cat = new Cat(); Dog dog = new Dog(); Thread threadCat = new Thread(cat); Thread threadDog = new Thread(dog); threadCat.start(); threadDog.start(); } public static void main(String[] args) { for (int i = 0; i < 3; i++) { System.out.println("Main thread"); } new ThreadExercise().start(); } }
9
收起
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星