SystemVerilog OOP Mastery · All levels
clone() and copy() Methods: Interview Questions
Interview Questions for clone() and copy() Methods.
Interview questions
Q1. Why keep both copy and clone instead of just clone?
Answer: copy allows reuse for already-allocated objects and inheritance layering, while clone standardizes fresh-object creation.
Q2. What should derived copy do first and why?
Answer: Call super.copy(rhs) first so base-state transfer remains centralized and cannot be forgotten.
Q3. How do you prevent derived-field copy on wrong runtime type?
Answer: Use $cast to derived type before accessing derived fields; skip or error on failure.