0

When we tried to run the following program then it successfully runs.

class with {
    public static void main(String args[]) {
        System.out.println("With static");
    }
}

but even if we tried to run the following program it did't ran successfully.

class without {
    public void main(String args[]) {
        System.out.println("With static");
    }
}

we know becuase in this program we have't use static in main() method. So, we want to ask that the : - is it possible to run java program without static ? if is it possible then how can i do this.

Manohar Kumar
  • 605
  • 9
  • 12

2 Answers2

0

No that is not possible.

Why?

The first method (main) needs to be static, i.e context-free.

You cannot start your program with already instanciated objects, variables, etc...

Jean Logeart
  • 52,687
  • 11
  • 83
  • 118
0

No.

To run without static, you'd first have to have an object to invoke that method from (using new). Where would you put the instruction to create that object? In a non-static method? That needs an object to invoke that from... Where would you put the instruction to create that object? In a non-static method? That needs an object to invoke that from... Where would you put the instruction to create that object? In a non-static method? That needs an object to invoke that from...

pcalcao
  • 15,789
  • 1
  • 44
  • 64