Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another version of main method

 
nish vatsa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just try dis:

public static void main(String... args) {
System.out.println("nis");
}


It will compile fine and morever it run correctly and output is nish
 
Amit Sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check it again its not working
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no its not working. which version of java are you using?. i am using 1.4.2_05.
 
nish vatsa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its working fine

public class Test {
public static void main(String... args) {
System.out.println("nis");
}


}

u r missing somewhere...
 
nish vatsa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just check the JLS specification at

http://java.sun.com/docs/books/jls/third_edition/html/execution.html

it mentioned as .........

The method main must be declared public, static, and void. It must accept a single argument that is an array of strings. This method can be declared as either


public static void main(String[] args)

or

public static void main(String... args)

i ran it using jdk1.5
 
Enge Chall
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That varargs is jdk 1.5 upward compartible. enjoy !!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic