0
 public class Sample2 {

    int a=11;
 int b = 22;
}
class DemoBus extends Sample2 {
    int a=25;
    int b=26;
    void m1(){
    System.out.println("demo class m2");
    }
}
class TestBus extends DemoBus
{
    int d=65;
    int e = 78;
    void m2(){
        System.out.println("sample class m2");
    }
    void m3(){
        System.out.println("sample class m3");
    }
void show()
{
    int a=45;
    int c=90;
    TestBus t = new TestBus();
    System.out.println(t.a);
    System.out.println(super.a);
    System.out.println(c);
    System.out.println(this.a);
    System.out.println(d);
    System.out.println(a);
    m1();
    m2();
m3();

}
public static void main(String ar[])
{
    TestBus s = new TestBus();
    s.show();
}
}

I tried to execute it but it is not executing. I tried with 'public' kept for TestBus, still it's showing error. I also tried in cmd with TestBus then the code executed and output is displayed but in ide its showing error.

Ankit Shubham
  • 2,989
  • 2
  • 36
  • 61

1 Answers1

-1

You should put main method in the public class in your case Sample2 and it should work!

I have tried it in NetBeans and it works.

The problem whith your code is that your .java file is named Sample2 and when your program is executed by JRE, it does not find your main method inside your source files (.java files) even if your method is static.

V. Sambor
  • 12,361
  • 6
  • 46
  • 65