老师请检查
来源:2-8 自由编程
阿山123
2021-03-31 16:55:59
package com.imooc.runnableone;
class Cat implements Runnable{
@Override
public void run() {
for(int i=0;i<3;i++) {
System.out.println(Thread.currentThread().getName() +",我在执行第"+ (i+1)+"次 A cat");
}
}
}
class Dog implements Runnable{
@Override
public void run() {
for(int i=0;i<3;i++) {
System.out.println(Thread.currentThread().getName()+",我在执行第"+ (i+1)+"次 A Dog");
}
}
}
public class Test {
public static void main(String[] args) {
for(int i=0;i<3;i++) {
System.out.println(Thread.currentThread().getName()+" thread");
}
Dog dog=new Dog();
Thread th1=new Thread(dog,"我是线程1");
th1.start();
Cat cat=new Cat();
Thread th2=new Thread(cat,"我是线程2");
th2.start();
}
}
1回答
同学你好,已完成练习,棒棒哒!继续加油!
祝学习愉快!
相似问题