# Strange behaviour when variable is re-declared in the extended class

**URL:** <https://verificationacademy.com/forums/t/strange-behaviour-when-variable-is-re-declared-in-the-extended-class/33924>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog\
**Created:** [January 15, 2018, 6:41am UTC](https://verificationacademy.com/forums/t/strange-behaviour-when-variable-is-re-declared-in-the-extended-class/33924 "2018-01-15T06:41:26Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![S.P.Rajkumar.V](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@S.P.Rajkumar.V](https://verificationacademy.com/forums/u/S.P.Rajkumar.V)\
**Post date:** [January 15, 2018, 8:46pm UTC](https://verificationacademy.com/forums/t/strange-behaviour-when-variable-is-re-declared-in-the-extended-class/33924/2 "2018-01-15T20:46:54Z")

</div>

_In reply to [abhi\_inno](https://verificationacademy.com/forums/t/strange-behaviour-when-variable-is-re-declared-in-the-extended-class/33924):_

This is Inheritance+Over-riding.

When you extend any class, the extended class inherits the parents members and methods. Because of which, when you create(new) an extended class, all the members/functions in Parent are also created along with the additional members/functions in the extended class.

So, in your example when child is created (new()), memory will be allocated to two color variables one for parent ‘color’ and one for child ‘color’. And when you try to access color from the respective handles the respective values are printed.

---

_[View the full topic](https://verificationacademy.com/forums/t/strange-behaviour-when-variable-is-re-declared-in-the-extended-class/33924)._
