1、两台打印机同时工作,请彭彭老师检查,辛苦老师!
来源:16-20 测评作业

mottoyin
2025-02-22
PrintThread类
package com.imooc.chapter16test;
public class PrinterThread extends Thread{
private String name; //打印机名
//含参构造方法
public PrinterThread(String name) {
this.name = name;
}
//重写父类的run()方法
@Override
public void run(){
//for循环输出打印信息
for (int i = 1; i <= 10 ; i++) {
System.out.println(this.name + "--正在打印第" + i + "张纸");
}
}
}
测试类
package com.imooc.chapter16test;
public class PrinterThreadTest{
public static void main(String[] args) {
//实例化Thread子类对象
PrinterThread thread1 = new PrinterThread("打印机1");
PrinterThread thread2 = new PrinterThread("打印机2");
//启动线程
thread1.start();
thread2.start();
}
}
写回答
1回答
-
彭彭老师
2025-02-23
没有问题
00
相似问题