By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,798 Members | 1,378 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,798 IT Pros & Developers. It's quick & easy.

Help with Java Debugging

P: 33
Plz help me in correcting this code: It compiles but when i execute it gives error: Exception in thread "main" java.lang.NoSuchMethodError: main

Expand|Select|Wrap|Line Numbers
  1.  
  2. class Animal {
  3.       public void eat(){
  4.  
  5.       System.out.println("Animal eats");
  6.       }
  7. }
  8.  
  9. class Dog extends Animal {
  10.       public void eat(){ 
  11.           System.out.println("Dog eats");
  12.       }
  13.  
  14.  public static void main(String[] args){
  15.        Animal a = new Dog();
  16.        Dog d = new Dog();
  17.        Animal d2 = (Animal) d;
  18.        d.eat();
  19.        a.eat();
  20.        d2.eat();
  21.       }
  22. }
Mar 23 '12 #1
Share this Question
Share on Google+
2 Replies


10K+
P: 13,264
You should be running Dog class because it's the one that has the main method not the Animal class. Or better, put the main class in it's own public class and run that Tester class.
Mar 24 '12 #2

P: 33
I worked on it.

Thanks.. it worked
Mar 26 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.