+ 2

What is the benifit of defining the main method inside the class in java?

18th Jun 2017, 2:01 PM
dharshini😎
dharshini😎 - avatar
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 .
18th Jun 2017, 2:17 PM
Utkαrsh
Utkαrsh - avatar
+ 5
Everything in java has a class
18th Jun 2017, 3:11 PM
Siddharth Saraf
+ 4
I know main method is important ,but why it is defined inside the class?
18th Jun 2017, 2:51 PM
dharshini😎
dharshini😎 - avatar
+ 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 .
18th Jun 2017, 4:01 PM
Utkαrsh
Utkαrsh - avatar