a- /**
- * 需求:设计一个电影售票程序,共一百张票,有三个售票窗口
- *
- */
- package test;
- public class SellTicket {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- method1();
- // method2();
- }
- //方式二:继承模式实现
- private static void method2() {
- // TODO Auto-generated method stub
- Thread t1 = new Thread(new Ticket(),"widow 1");
- System.out.println("t1的名字:"+t1.getName());
- t1.start(); //启动窗口1
- // System.out.println(Thread.currentThread().getName());
- new Thread(new Ticket(),"widow 2").start();//启动窗口2
- new Thread(new Ticket(),"widow 3").start();//启动窗口3
-
- }
- //方式一:继承方式
- public static void method1(){
- //创建对象
- Ticket t1 = new Ticket("window 1");
- Ticket t2 = new Ticket("window 2");
- Ticket t3 = new Ticket("window 3");
- //启动线程
- t1.start();
- t2.start();
- t3.start();
-
- }
-
- }
复制代码
|
|