SystemVerilog OOP Mastery · All levels
Pure Virtual Methods as Compile-Time Contracts: Interview Questions
Interview Questions for Pure Virtual Methods as Compile-Time Contracts.
Interview questions
Q1. What problem do pure virtual methods solve better than comments or style guides?
Answer: They make required behavior enforceable by the language, so incomplete implementations fail at compile/elaboration time instead of failing later in simulation.
Q2. When should a method be pure virtual versus regular virtual with default body?
Answer: Use pure virtual when every concrete subclass must provide behavior. Use regular virtual with defaults when a safe generic behavior exists and overriding is optional.
Q3. Can you invoke a pure virtual method via a base handle?
Answer: Yes, as long as the runtime object is a concrete subclass that implemented the method; dispatch resolves to that implementation.