Help with Java Debugging

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chintan85
    New Member
    • Jun 2010
    • 33

    Help with Java Debugging

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

    Code:
    class Animal {
          public void eat(){
    
    	  System.out.println("Animal eats");
          }
    }
    
    class Dog extends Animal {
          public void eat(){ 
              System.out.println("Dog eats");
          }
    
     public static void main(String[] args){
           Animal a = new Dog();
           Dog d = new Dog();
           Animal d2 = (Animal) d;
           d.eat();
           a.eat();
           d2.eat();
          }
    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    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.

    Comment

    • chintan85
      New Member
      • Jun 2010
      • 33

      #3
      I worked on it.

      Thanks.. it worked

      Comment

      Working...