- public class CoalDemo {
- public static void main(String[] args) {
- Coal c1 = new Coal("煤一","1吨"); //创建对象
- Coal c2 = new Coal("煤二","2吨");
- Thread t1 = new Thread(c1); //创建线程
- Thread t2 = new Thread(c2);
- t1.start(); //线程启动
- t2.start();
- }
- }
- class Coal implements Runnable {
- private String name;
- private String value;
-
- Coal(String name, String value) { //构造参数传入值
- this.name = name;
- this.value = value;
- }
- public void run() {
-
- for(int y=0;y<2000;y++){
-
- System.out.println(name + "...."+ value);
-
- }
- }
-
- }
复制代码 |