← Quiz: Shallow and Deep Copy: all 10 questions
Quiz: Shallow and Deep Copy · Question 8 of 10
Why do many Java developers prefer a copy constructor over clone()?
Why do many Java developers prefer a copy constructor over clone()?
- A.Copy constructors are always faster
- B.It runs normal constructor code, works with final fields and needs no cast or checked exception
- C.clone() was removed from Java
- D.Copy constructors make deep copies automatically
Answer & explanation
Correct answer: It runs normal constructor code, works with final fields and needs no cast or checked exception
A copy constructor is ordinary code where you decide how each field is copied.
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 →