+ 2
What is the benifit of defining the main method inside the class in java?
5 Antworten
+ 7
It's the part of basic syntax , without main method Java program won't run .
It's the place where everything is done or called , the compiler runs only main method through which other method are executed if they are called inside them , methods aren't executed they aren't called inside main .
+ 5
Everything in java has a class
+ 4
I know main method is important ,but why it is defined inside the class?
+ 4
@dharshini Because classes and methods are the building blocks of OOP as @Serena said , atleast one class is required to do something without it the code won't run .
Main is just like other methods , it has to be placed inside a class just like any other method .