Given the code fragment:
What is the result?
A.
Sum is 600
B.
Compilation fails at line n1.
C.
Compilation fails at line n2.
D.
A ClassCastException is thrown at line n1.
E.
A ClassCastException is thrown at line n2.
Given the code fragment:
What is the result?
A.
Sum is 600
B.
Compilation fails at line n1.
C.
Compilation fails at line n2.
D.
A ClassCastException is thrown at line n1.
E.
A ClassCastException is thrown at line n2.
Answer is C. The line at n1 works fine because of the cast.
However s1 + s2 returns an int and we cannot pass an int value into a String reference variable without using a method like String.valueOf(long l)
ie
String s4 = String.valueOf(s3 * s2);
would create a string containing “240000”
*** s1 + s2*** supposed to be s3*s2 on second line and that returns a long