| Author |
string + int
|
javi cervera
Greenhorn
Joined: Jan 17, 2002
Posts: 16
|
|
this code compile: String s = "hello" + 7 ; ok but this compile also? String s = 7 + "hello"; in my compiler yes, but i have read in certification books that this code not compile. What is the answer in the exam? Thanks in advance.
|
 |
manasa teja
Ranch Hand
Joined: May 27, 2002
Posts: 325
|
|
yes. In both the cases, 7 will be converted into string and will be concatenated to hello
Originally posted by wasarta: this code compile: String s = "hello" + 7 ; ok but this compile also? String s = 7 + "hello"; in my compiler yes, but i have read in certification books that this code not compile. What is the answer in the exam? Thanks in advance.
|
MT
|
 |
Jose Botella
Ranch Hand
Joined: Jul 03, 2001
Posts: 2120
|
|
Wellcome to the Ranch wasarta. Please read our namimg policy and change your displayed name accordingly.
|
SCJP2. Please Indent your code using UBB Code
|
 |
Ron Newman
Ranch Hand
Joined: Jun 06, 2002
Posts: 1056
|
|
|
The Java compiler treats + as string concatenation if either operand is a String.
|
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
|
 |
Anthony Villanueva
Ranch Hand
Joined: Mar 22, 2002
Posts: 1055
|
|
The order is important, though. See this sample code:
|
 |
 |
|
|
subject: string + int
|
|
|