IntelliJ Java IDE
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A question about the main() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "A question about the main() " Watch "A question about the main() " New topic
Author

A question about the main()

Michelle Chang
Greenhorn

Joined: Jan 22, 2010
Posts: 8
A question about the main(); Can we take var-arg as the argument of the Main()? Are these two legal as the argument of the Main()? Thanks.



Always speak up for stupid questions.
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
There are three alternatives of main, all are equivalent:
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

var-arg as be used as a replacement of an array
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Michelle Chang wrote:A question about the main(); Can we take var-arg as the argument of the Main()? Are these two legal as the argument of the Main()? Thanks.



I think, your first code is wrong, second is correct!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2595

Michelle Chang wrote:Are these two legal as the argument of the Main()?

What's happened when you tried?


Author of ExamLab - the free mock exam kit for SCJP / OCPJP
Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
bhanu chowdary
Ranch Hand

Joined: Mar 09, 2010
Posts: 256
The first one will not compile
Ganesh Dhakshinamurthy
Greenhorn

Joined: Apr 08, 2007
Posts: 11
When i tried the first one, it compiled and executed successfully. Am I missing something here?

Afzal Rehman
Ranch Hand

Joined: Dec 16, 2009
Posts: 35
Both codes works!
even Which i figure out after do some testing...
codes works.

Let say




Which my conclusion it's works with var-args and Arrays without spaces ... in any method
but It will not compile with primitive and Object etc.

It's something to do with Arrays but if someone put some Green Light on it it would be helpful to
understand the reason....

SCJP 6.0
 
 
subject: A question about the main()
 
Threads others viewed
Mughal's Mock Exam-Main method declaration
Simple java error need some advice please
main method declaration doubt!
Fill in the blank
getting list of JRE args
IntelliJ Java IDE