2-8自由编程
来源:2-8 自由编程
慕神0457710
2020-08-22 02:22:27
public class Cat implements Runnable{ @Override public void run() { for (int i=1;i<4;i++) { System.out.println(Thread.currentThread().getName()+"A cat"); } } }
public class Dog implements Runnable { @Override public void run() { for (int i=1;i<4;i++) { System.out.println(Thread.currentThread().getName()+"A dog"); } } }
public class Test { public static void main(String[] args) { for (int i=1;i<4;i++) { System.out.println("main thread"); } Cat cat1 = new Cat(); Thread th1 = new Thread(cat1); th1.start(); Dog dog = new Dog(); Thread th2 = new Thread(dog); th2.start(); } }
1回答
同学你好,同学已完成练习,棒棒哒!
如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
相似问题