wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Problem : Threads ; Reference Cert Pal 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Problem : Threads ; Reference Cert Pal 2" Watch "Problem : Threads ; Reference Cert Pal 2" New topic
Author

Problem : Threads ; Reference Cert Pal 2

Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
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 ???


SCJP 6.0 96%

(Connecting the Dots ....)
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

That code won't even compile, there are brackets instead of braces in the class declaration...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Corrected..that was my typo !!!
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

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.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Feb 24, 2006
Posts: 6661
    
    5

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

Joined: Jan 28, 2008
Posts: 5575

ok deepak, corrected my opinion. thanks
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
The question was like that only.....even i am confused
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem : Threads ; Reference Cert Pal 2
 
Similar Threads
thread problem
daemon -boolean variable
wait, notify and notifyAll
sleep()
Do different types of Threads exist in JAVA?