• 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

Is MyRunnable Abstract??

 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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..
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic