Question 1721
public class Tag
{
private String text;
public Tag(String t)
{
text = t;
}
public void add(String s)
{
text = text + s;
}
public String show()
{
return text;
}
}
Tag x = new Tag("AP");
Tag y = new Tag("C");
y = x;
x.add("CSA");
System.out.println(x.show() + " " + y.show());
Main Solution
Answer
Answer: A. After y = x, both variables refer to the same Tag object. Appending "CSA" through x changes that shared object, so both method calls return "APCSA".
Answer: Correct: A
A
APCSA APCSA
B
APCSA C
C
AP APCSA
D
C APCSA
Answer images

