Polymorphism allows the use of a variable of the base class type to hold subclass objects and to reference the methods of those subclasses directly from the superclass variable.

Assign Child Class to Base Class

Taking the same example from Inheritance, we'll assign a sub/child class instance sc to a base class handle bc.

module tb;
	Packet      bc; 	// bc stands for BaseClass
	ExtPacket   sc; 	// sc stands for SubClass

	initial begin
		sc = new (32'hfeed_feed, 32'h1234_5678);
		bc = sc;
		bc.display ();
		sc.display ();

Login to your free account to read more ...

Was this article helpful ?