• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question about String[]???

 
tanu dua
Ranch Hand
Posts: 145
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read one question in one of the mock of SCJP.

Output: Code will compile correctly and will print "In first main()" (without quotes) when run with argument of 'a'.
Now i am facing the problem how the character value 'a' can be coverted to String type.
Thanx!!!
Edited by Corey McGlone: Added CODE Tags
[ April 13, 2004: Message edited by: Corey McGlone ]
 
Corey McGlone
Ranch Hand
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by tanu dua:
Now i am facing the problem how the character value 'a' can be coverted to String type.

Hmm... Nowehere in that code is a char converted to a String type. Unless, you're referring to the output line which is never executed.
In such a case, the println method is making use of Character.toString().
I hope that helps,
Corey
 
Mark Patrick
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are getting confused on the overloaded main method. When you run this class as follows:
java MyClass a
The JVM will always look for a method in MyClass with the signature "public static void main(String[] args)" and pass the "a" into the first element of the String array.
The overloaded method "public static void main(char args[])" will never be executed when you run MyClass, even if you pass what appears to be the char value 'a' in the command line argument. The only way that this method can be executed is if you call it from inside of your already running program.
 
Lionel Orellana
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Patrick:
The overloaded method "public static void main(char args[])" will never be executed when you run MyClass, even if you pass what appears to be the char value 'a' in the command line argument.

Wich is to say everything you pass to your program in the command line will be a String.
java MyClass 1 2 sss 'a'
1, 2, sss, and 'a' are passed as Strings to your main method ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic