Thursday 28 February 2013

In how many different ways can we declare a main method in java?

Ways of declaring main methods in Java:

  1. public static void main(String[] args) or public static void main(String args[])
  2. public static void main(String... args). The positions of public and static may change as the programmer wish. But remember void should always come before main method. You can also use any parameters for the main method but the main with String[] args will only be executed first. You can also execute a java program without a main method. For this you need to make use of static block with a break statement at the end.

No comments:

Post a Comment