Welcome Guest | Sign in | Register
java.lang.class - Discussion Page For Q.2897 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > java.lang.class > Questions and Answers

Exercise:

Section 1

Q: What will be the output of the program?

String x = "xyz";
x.toUpperCase(); /* Line 2 */
String y = x.replace('Y', 'y');
y = y + "abc";
System.out.println(y);
A. abcXyZ B. abcxyz
C. xyzabc D. XyZabc

Answer and Explanation

Answer:xyzabc

Explanation:
Line 2 creates a new String object with the value "XYZ", but this new object is immediately lost because there is no reference to it. Line 3 creates a new Stringobject referenced by y. This new String object has the value "xyz" because there was no "Y" in the String object referred to by x. Line 4 creates a new Stringobject, appends "abc" to the value "xyz", and refers y to the result.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.