• 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

A Question for beginners - 2

 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code will not get compiled.
Because...
To create a Thread class should either extend Thread class or implement Runnable interface.
Thanks & Regards
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
reply
    Bookmark Topic Watch Topic
  • New Topic