• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A question about String[]???

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ...
 
reply
    Bookmark Topic Watch Topic
  • New Topic