class MyThread1 implements Runnable { Thread t; MyThread1() { t = new Thread(this);//create a Thread t.start();//activate the thread } public void run() //override run() of Runnable { int i; for(i =0; i< 1000; i++) System.out.print("*"); } public static void main(String args[]) { MyThread1 m1 = new MyThread1(); int i; for(i =0; i< 1000; i++) System.out.print("="); } }
The class creates a reference of the Thread class(Line 3). How is this possible given that Thread class is not extended by it?
Because on line 7 you have a new Thread(...), so there you create a Thread instance, just like you can create a String or any other kind of Object.