← Quiz: Shallow and Deep Copy: all 10 questions
Quiz: Shallow and Deep Copy · Question 1 of 10
What does this print? (code)
What does this print?
class Box {
int value;
Box(int value) { this.value = value; }
}
public class Main {
public static void main(String[] args) {
Box a = new Box(5);
Box b = a;
b.value = 10;
a = new Box(20);
System.out.println(a.value + " " + b.value);
}
}
- A.10 10
- B.20 20
- C.20 10
- D.5 10
Answer & explanation
Correct answer: 20 10
b still points to the first Box (changed to 10); a was re-pointed to a new Box with 20.
Can you get the rest right without peeking?
Take the timed Quiz: Shallow and Deep Copy quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →