sravanTG
sravanTG

Reputation: 714

Cannot find main method in class Super

I am trying to run this code but its giving me the error that it cannot find main method. how to fix this error?by defining main method in super class,we cannot run the other classes so how to fix it?

class Super {

int x;

void Super(int x) {
    this.x= x;
}

void display() {
    
    System.out.println("super x = " + x);
    
}

}

 class sub extends Super {
     
     int y;
     
     void sub(int x , int y) {
         Super(x);
         this.y = y;
        
         System.out.println("super x = " + x);
         System.out.println("super y = " + y);
     
     }
         
     public static void main(String args[]) {
         
         sub s1 = new sub();
         s1.sub(100, 200);
         s1.display();
        
     }
     
 }

Upvotes: 0

Views: 313

Answers (1)

Edgar Magallon
Edgar Magallon

Reputation: 559

Your file name must be sub.java I guess you have your file name like Super.java, for that reason, when you execute the file, it throws an error. Because is searching the main method inside Super class.

Upvotes: 1

Related Questions