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 Programmer Certification (SCJP/OCPJP) and the fly likes Is MyRunnable Abstract?? 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 "Is MyRunnable Abstract??" Watch "Is MyRunnable Abstract??" New topic
Author

Is MyRunnable Abstract??

sonir shah
Ranch Hand

Joined: Nov 01, 2001
Posts: 435
[CODE}
class MyRunnable implements Runnable
{
public static void main(String[] args)
{
new Thread( new MyRunnable(2) ).start();
}
public void run(int n)
{
for(int i=0; i<n; i++)
{
System.out.println("Hello World");
}
}
}
[/CODE]
I tried running this code, but it shows a compile time error saying that MyRunnable should be declared Abstract.
But there is no Abstract method in class MyRunnable???
Please explain..
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
You are trying to instantiate MyRunnable with a constructor taking one argument and you haven't declared any constructor. By default you only have the default constructor taking no arguments.
Moreover you declare the run method taking one parameter and whereas the run method of the Runnable interface doesn't take any arguments. The compiler says that MyRunnable should be declared abstract because there is no method run() with no parameters...
[ January 11, 2002: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is MyRunnable Abstract??
 
Similar Threads
myThread.isAlive() v.s. WeakReference ? URLyBird 1.2.2 using Socket
Thread Question -JQ++
Overriding the start method of Thread Class
Thread Doubt
Thread question - uCertify 6.0