This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes A Question for beginners - 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 » Java » Threads and Synchronization
Bookmark "A Question for beginners - 2" Watch "A Question for beginners - 2" New topic
Author

A Question for beginners - 2

Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1846
Without compiling what is the result of executing the following program. why??
I recommend you not see others replies and post your replies.

Regds.
Rahul P. Mahindrakar
V Srinivasan
Ranch Hand

Joined: Aug 16, 2000
Posts: 99
This code will not get compiled.
Because...
To create a Thread class should either extend Thread class or implement Runnable interface.
Thanks & Regards
vidya
Ranch Hand

Joined: Aug 08, 2000
Posts: 47
hi!
Rahul, this is a really nice thing you do.... I think it really helps beginners like me...Thanks a lot...
About the code,
Well, the class demo1 doesnt implement the Runnable interface,
and the argument passed to the constructor new Thread(p) must be an object that implements Runnable.The compiler will point out that.(but I am not sure what exactly the error message will be..)
Or, the class demo1 should extend the Thread class so the method run() is available to it by inheritance...
Could you let me know what the error message will be?
thanks again...
Vidya.

Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1846
I made this post to make the point that implementing all the methods in the interface does not mean implementing the interface. In the code implementing the run method does not mean that one implements the Runnable interface. thus
Code 1:

is not the same as
Code 2:

Also the thread constructor not only takes a Runnable interface as a prarameter but can also take a Thread object as a parameter . for example

this is possible as the thread class itself is defined as
public class Thread extends Object implements Runnable
and since Thread class itself implements Runnable it can be passed as a parameter to the Thread constructor.
Vidhya,
Thanks for the complements. Complements really motivate.

Regds.
Rahul P. Mahindrakar


[This message has been edited by Rahul Mahindrakar (edited August 21, 2000).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A Question for beginners - 2
 
Similar Threads
constructor
Getting error in this code??? why is that so?
Daemon Threads
compound assignment operator behaving differently for Byte and byte
A question for All