标签:lap 接口 spl int 实现 启动 out 对象 pen
1.多线程
两种方式可以实现多线程:
class TDemo1 extends Thread { public String name; // 取个名字,便于识别 public TDemo1 (String name) { // 构造方法 this.name = name; } @Override public void run() { // 重写 run 方法 show(); } public void show() { System.out.println(name + ": talk show time"); } }
TDemo1 td1 = new TDemo1("梁宏达"); TDemo1 td2 = new TDemo1("李晨伟"); TDemo1 td3 = new TDemo1("窦文涛"); TDemo1 td4 = new TDemo1("备胎说车"); td1.start(); td2.start(); td3.start(); td4.start();
class TDemo2 implements Runnable { public String name; // 识别 public TDemo2(String name) { // 构造方法 this.name = name; } @Override public void run() { // 实现方法 show(); } private void show() { System.out.println(name + " 新媒体开播"); } }
Thread td1 = new Thread(new TDemo2("备胎说车")); Thread td2 = new Thread(new TDemo2("30秒懂车")); Thread td3 = new Thread(new TDemo2("汽车洋葱圈")); Thread td4 = new Thread(new TDemo2("根叔说车")); td1.start(); td2.start(); td3.start(); td4.start();
a
标签:lap 接口 spl int 实现 启动 out 对象 pen
原文地址:https://www.cnblogs.com/argor/p/9076222.html