# Inheritance and Polymorphism

**URL:** <https://verificationacademy.com/forums/t/inheritance-and-polymorphism/39482>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, Polymorphism, inheritence\
**Created:** [August 26, 2021, 4:58pm UTC](https://verificationacademy.com/forums/t/inheritance-and-polymorphism/39482 "2021-08-26T16:58:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarshallX](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@MarshallX](https://verificationacademy.com/forums/u/MarshallX)\
**Post date:** [August 26, 2021, 4:58pm UTC](https://verificationacademy.com/forums/t/inheritance-and-polymorphism/39482/1 "2021-08-26T16:58:21Z")

</div>

```verilog
class base;

  task A;
    $display("A called");
    B();
  endtask

  virtual task B;
    $display("B Called");
  endtask
endclass

class child extends base;

  task B;
     $display("B EXT called");
  endtask

  task super_A();
     super.A();
  endtask

endclass

module test;
  initial begin
      base bh;
      child ch;
      ch = new();
      ch.A;
      bh = ch;
      bh.super_A();
  end
endmodule

```

What is the output of this code?

---

<div class="post-metadata">

**Author:** ![harsh\_pandya](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/harsh_pandya/32/2973_2.png) [@harsh\_pandya](https://verificationacademy.com/forums/u/harsh_pandya)\
**Post date:** [August 26, 2021, 5:21pm UTC](https://verificationacademy.com/forums/t/inheritance-and-polymorphism/39482/2 "2021-08-26T17:21:16Z")

</div>

_In reply to [MarshallX](https://verificationacademy.com/forums/t/inheritance-and-polymorphism/39482):_

It will issue compile time error.  
Like, super\_A not found in “bh”. As super\_A not part of base class.  
What is your query on this. I mean what is your expectations ?

Thanks!

---

<div class="post-metadata">

**Author:** ![shanthi](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@shanthi](https://verificationacademy.com/forums/u/shanthi)\
**Post date:** [August 27, 2021, 8:20am UTC](https://verificationacademy.com/forums/t/inheritance-and-polymorphism/39482/3 "2021-08-27T08:20:01Z")

</div>

_In reply to [MarshallX](https://verificationacademy.com/forums/t/inheritance-and-polymorphism/39482/2):_

Using parent class handle we can access only the overridden virtual methods of child class. As the method super\_A is not the overridden virtual method in child class we can not access it using parent handle.

---

<div class="post-metadata">

**Author:** ![MarshallX](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@MarshallX](https://verificationacademy.com/forums/u/MarshallX)\
**Post date:** [September 4, 2021, 9:20am UTC](https://verificationacademy.com/forums/t/inheritance-and-polymorphism/39482/4 "2021-09-04T09:20:03Z")

</div>

_In reply to [shanthi](https://verificationacademy.com/forums/t/inheritance-and-polymorphism/39482/3):_

> _In reply to [MarshallX](https://verificationacademy.com/forums/t/inheritance-and-polymorphism/39482/3):_  
> Using parent class handle we can access only the overridden virtual methods of child class. As the method super\_A is not the overridden virtual method in child class we can not access it using parent handle.

Thanks much for the information. It’s true with overridden virtual functions.
