SystemVerilog OOP Mastery · All levels
Virtual Methods and Override Intent: Exercises
Exercises for Virtual Methods and Override Intent.
Practice exercises
Exercise 1
Given base handle comp; comp = new my_comp(); comp.report(); comp.build_phase(); make report dynamically dispatch too.
Solution
diagram
Declare report as virtual in the base class. Keep matching signature in my_comp. Calls through comp will then select my_comp::report at runtime.Exercise 2
Your UVM packet override compiles but custom fields never print. Identify the likely virtual-related root cause and fix.
Solution
diagram
Check that the hook method is a true virtual override of the framework method (usually do_print). Match signature exactly and keep virtual in the base declaration.