Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
The result of i = ((int)((string)((int)"7")+"5"))
a) An integer i, where i = 12
b) A String, i where i = 12
c) A String, i where i = 75
d) An integer i, where i = 75
e) An Exception


Would you mind to explain what I need to figure out fron i = ((int)((string)((int)"7")+"5"))
Posted

1 solution

Your answer would be d.

7 is first converted to an integer.
7 is then implicit y converted to a string and concatenated to 5 thus giving you 75 as a string.
This is then again converted to an integer thus giving you integer 75.
 
Share this answer
 
Comments
Member 10811352 12-May-14 2:04am    
God bless you. I was thinking completely different way.
so the last stage is D where converted to Integer from String or last stage is String converted from integer which is C
Abhinav S 12-May-14 2:23am    
I would recommend you run this line in Java and check the output.
Member 10811352 12-May-14 2:37am    
I could not examine the code by following because error message can't cast String to int
public static void printnum1() {

int i;

i = ((int)((string)((int)"7")+"5"));

System.out.println(i);
}
Abhinav S 12-May-14 3:24am    
In that case, this question is wrong and you will get an compile error.
Member 10811352 12-May-14 3:30am    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900