• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem : Threads ; Reference Cert Pal 2

 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of these classes are valid threads ?


Correct option is :- class Big4 implements Runnable { public void run() {}}

IMO :- It is not a Thread since it is not extending Thread class ???

 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That code won't even compile, there are brackets instead of braces in the class declaration...
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Corrected..that was my typo !!!
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Threads can be formed by either extending from the Thread class or implementing the runnable interface. In this case the class implements the interface.

The Thread class by itself implements the Runnable interface.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sahil Kapoor wrote:
Which of these classes are valid threads ?
Correct option is :- class Big4 implements Runnable { public void run() {}}
IMO :- It is not a Thread since it is not extending Thread class ???

question is not clear! if it would be Which of these classes are valid to start a thread on that? then Big4 is ok. in java every object is a thread, means all the object[ which are extends Thread or implements Runnable]can be accessible by threads. actually, Runnable gives the thread design to a class such as it must implement run method. and of course you can implement your own thread creation in that class like java.lang.Thread. but in general , you need java.land.Thread class to start a thread
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in java every object is a thread,


This is an incorrect statement

which are extends Thread or implements Runnable]can be accessible by threads


If you meant that all classes that extend Thread or implement Runnable qualify as threads, you are right. Which is what the question asks a developer to identify.

but in general , you need java.land.Thread class to start a thread


The question is about a valid representation / definition of a thread and not about starting threads.

This article about a Thread written by Sun / Oracle can clear it up. Notice that a thread can be 'defined' using a Runnable interface if necessary -> http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/essential/concurrency/runthread.html
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok deepak, corrected my opinion. thanks
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question was like that only.....even i am confused
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic