my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Another question from marcus green mock exam 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 "Another question from marcus green mock exam" Watch "Another question from marcus green mock exam" New topic
Author

Another question from marcus green mock exam

Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442

The above code compiles & runs fine.Shouldn't it give compile time error?Coz run method of Thread class is not overriden in child class?


SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Vivek Nidhi
Ranch Hand

Joined: Aug 10, 2003
Posts: 133
I hope if a class extends another class, its not mandatory to implement or override the methods in the super class. Only in case of implementing interface, we need to implement the interface methods or declare the sub class as abstract
Vivek Nidhi

[ October 20, 2003: Message edited by: Vivek Nidhi ]
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
You don't have to override run() to compile unless you implement Runnable interface in a concrete class. This code seems to be fine, no new thread is created because the start() method is overridden and called just like any other regular method. Hope this helps.
Thomas De Vos
stable boy
Ranch Hand

Joined: Apr 12, 2003
Posts: 425
The Holt class does not need to implement the run() method of the interface Runnable.
The class Thread implements the defintion of the run() method. The run() method will call the start() method of the Thread class, unless the sub-class implements the start() method. This is the case in the Holt class and this is also the place where you will put you Thread logic.
This is one way of starting a Thread. The other way is implementing the Runnable interface (actually the same as what the Thread class does). That class then implements the run method. An instance of the class can then be allocated, passed as an argument when creating Thread, and started.
PS: I don't like sub-classing the Thread class, I prefer to work with Interfaces.
Thomas De Vos
http://www.javacertificate.com
http://www.j2eecertificate.com


Try your free <a href="http://www.javacertificate.com" target="_blank" rel="nofollow">SCJP 1.4</a> certification centre.<br />Try your free <a href="http://www.j2eecertificate.com" target="_blank" rel="nofollow">SCWCD</a> certification centre.<br />Try your free <a href="http://www.ejbcertificate.com" target="_blank" rel="nofollow">SCBCD</a> certification centre.<br />Try your <a href="http://www.webspherecertificate.com" target="_blank" rel="nofollow">Websphere (Test 285) </a> certification centre.<br />Try your <a href="http://www.j2mecertificate.com" target="_blank" rel="nofollow">SCMAD</a> certification centre. (New)<br /> <br /><a href="http://blogs.javacertificate.com" target="_blank" rel="nofollow">Java/J2EE Certification Blogging</a>
 
Don't get me started about those stupid light bulbs.
 
subject: Another question from marcus green mock exam
 
Similar Threads
Another question from marcus green mock exam
Thread
Question on Thread
thread
synchronize