• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem : Threads ; Reference Cert Pal 2

 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ???

 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Corrected..that was my typo !!!
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok deepak, corrected my opinion. thanks
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The question was like that only.....even i am confused
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic