Sunday, 29 January 2017

DIFFERENT WAYS OF WRITING MAIN METHOD IN JAVA

1.
public class Trial {
          public static void main(String[] args) {
                   System.out.println("Hello java");
          }
}

Note – The argument of main method is always of type String. We cannot take it other type like Integer, Float etc.

2.
public class Trial {
          public static void main(String... args) {
                   System.out.println("Hello java");
          }
}

Note – Instead of writing it as an array, we can use varargs.

3.
public class Trial {
          public static void main(String args[]) {
                   System.out.println("Hello java");
          }
}

4.
public class Trial {
          static public void main(String args[]) {
                   System.out.println("Hello java");
          }
} 

No comments:

Post a Comment