| Author |
Format
|
Balaji Bang
Ranch Hand
Joined: Apr 23, 2007
Posts: 180
|
|
Output is 1
I thought it will expect a String parameter and gives Runtime Exception.
But for gives error.
|
 |
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
|
|
Banu Chowdary wrote:
Output is 1
I thought it will expect a String parameter and gives Runtime Exception.
Have you looked at format() methods signature, it takes var arg type of Object., So 1 is autoboxed in Integer type. No Exception !
Banu Chowdary wrote:
But for gives error.
It doesn't give error, because it syntactically correct, but throws RuntimeException , stating "IllegalFormatConversionException: d != java.lang.String" , it means, you passed string and format specifier expect a Integer object or int.
|
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
|
 |
Punit Singh
Ranch Hand
Joined: Oct 16, 2008
Posts: 952
|
|
Banu remember Object class has toString() method and Integer class overrides this method.
so it will be converted to
As format method takes var-args. And Integer.toString() will be used to print String.
will be converted to
It will not run Object class does not have any method to convert String to Integer.
|
SCJP 6
|
 |
 |
|
|
subject: Format
|
|
|