//===============================================================
// This pgm shows that even main runs under a thread
// In java all programs run using Thread mechanism
// Here both classes are running under the same thread
//===============================================================
public class A1pgm
{
    public static void main(String[] args)
    {
        Class  c = A1pgm.class;                     //get reference to my class

        Thread t = Thread.currentThread();          //get reference to my thread

        System.out.println("This class name is: "   + c.getName() +
            ".   It is running under thread name: " + t.getName() );    

        A2class obj = new A2class();               //instantiate an object of A2
    }
}

class A2class 
{
    A2class( )                                      //constructor
    {       
        Class  c = A2class.class;                   //get a reference to my class           
//or    Class  c = this.getClass();                 //get a reference to my class (same as prev. line)

        Thread t = Thread.currentThread();          //get a reference to my thread

        System.out.println("This class name is: " + c.getName() +
            ". It is running under thread name: " + t.getName() );    
    }
}