954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Implementing Runnable interface inherits Thread class?

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?

slasherpunk
Newbie Poster
15 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

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.

JamesCherrill
Posting Genius
Moderator
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: