Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

threads

 
putti don
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Consider the following line of code :
Thread t = new Thread( anObjectOfMyClass );
Which of the following could be a valid declaration of MyClass?
1>MyClass extends Thread
2>MyClass implements Thread
3>MyClass implements Threadable
4>None of these.

the answer is option 4..My doubt is why can't it be option 1(as Thread class implements Runnable)?

Thanks.
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option 1 is valid, although it's not terribly interesting.

Compiles and runs just fine for me.
 
agrah upadhyay
Ranch Hand
Posts: 579
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But......Michael
Thread constructor don't take thread instance as argument.
As for as I know thread is having only following constructor possible:
So Option [4] should be valid...........Correct me iff i am wrong.....

Thread()

Thread(Runnable target)

Thread(Runnable target, String name)

Thread(String name)

Thread(ThreadGroup group, Runnable target)

Thread(ThreadGroup group, Runnable target, String name)

Thread(ThreadGroup group, Runnable target, String name, long stackSize)

Thread(ThreadGroup group, String name)
 
Jimmy Thomas
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Thread implements Runnable so it use the constructor

Thread(Runnable target)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic