Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Downcasting

Hardware interview practice

Downcasting

EasySystemVerilogSystemVerilog

What is the result of the cast?

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Starting point

Question code

class B; endclass
class D extends B; int tag = 9; endclass
B b; D original, d;
initial begin
  original = new;
  b = original;
  if ($cast(d, b)) $display("%0d", d.tag);
  else             $display("fail");
end
Choose one

Answer choices

  1. A. It prints 9
  2. B. It prints fail
  3. C. The cast allocates a new D and prints 0
  4. D. The cast is illegal because b is declared as B
Continue practicing

Related questions

SystemVerilogVirtual methods→SystemVerilogShallow copying→
asic.fyi · Learn silicon end to end.info@asic.fyi