这段代码加上main为什么会有四个线程

/*
* 实体类 Thread
* */
public class Ticket extends Thread{
    private Integer num=100;

    private Object obj=new Object();
    boolean flan=true;

    //重写Thread类的run方法供线程调用
    public void run(){
        while (flan){
            synchronized(obj){
                    try {Thread.sleep(20); } catch (InterruptedException e) { e.printStackTrace(); }
                    if (num>0){
                        System.out.println(Thread.currentThread().getName()+"..........."+num--);
                    }else {
                        flan=false;
                    }
            }
        }
    }

}

/*

  • 创建多线程
  • */
    public class Establish {
    public static void main(String args[]){

    //方式一:继承Thread类
    Ticket ticket=new Ticket();
    Ticket ticket2=ticket;
    Ticket ticket3=ticket;
    

    // Ticket2 ticket2=new Ticket2();
    Thread thread=new Thread(ticket);
    Thread thread2=new Thread(ticket2);
    Thread thread3=new Thread(ticket3);

    thread.start();
    thread2.start();
    ticket3.start();
    

    }
    }
    打印结果

Thread-2...........35
Thread-2...........34
Thread-3...........33
Thread-3...........32
Thread-3...........31
Thread-3...........30

main方法自身会起一个线程 你可以在main方法中打印一下线程名称看一下

一个进程至少一个线程,所以main本身就是一个线程,你另外启动3个,一共四个