Sunday, June 9, 2013

Define different main method format in Java

Do you know what do you mean of “public static void main()”?


It  is “access specifier” ; so it is basically define the scope of methods, classes and interface and etc.  you know JRE (Java Run-time Environment) is the outside part of class. if we use other access specifier (private, protected) so you can’t access the that class. If you are not used any access specifier. So compiler use the default access specifier.

In class there are two type members
      1-Instance member
          represent attributes and behavior of individual object. By default all the      member of class is instance member.
     2-class member
          represent attributes and behavior of whole class. Denoted  by  “static”   keyword.
So static keyword are used define the class member.

Functions are always requires a return type so void is one of them to returns value implicitly. If any error occur in the program so O.S returns the value with the help of  JRE.

only method name
Are you know the given below syntax are valid or not valid  in JAVA?

Syntex-(Modifier ReturnType MethodName() )

Static public void main (String [] arg ) true
Static public void main(String[][] arg) runtime error NoSuchMethodError
Static void public main (String [][] arg) compile time error
Void static public main (String arg[]) compile time error
 public static void main (String arg) runtime error NoSuchMethodError
Public void static main ([] String arg) compile time error
Public static void main (String[] arg[]) runtime error NoSuchMethodError
Public static void main() runtime error NoSuchMethodError

                                                 Author-Ravi Kumar