parameterize_and_inheritance 1
parameterize_and_inheritance 1
inheritance
Parameterized Classes
• Inheritance is an OOP concept that allows the user to create classes that are built upon
existing classes.
• The new class will be with new properties and methods along with having access to all the
properties and methods of the original class. Inheritance is about inheriting base class
members to the extended class.
• New classes can be created based on existing classes, this is referred to as class inheritance
• A derived class by default inherits the properties and methods of its parent class
• An inherited class is called a subclass of its parent class
• A derived class may add new properties and methods, or modify the inherited properties and
methods
• Inheritance allows re-usability. i.e. derived class by default includes the properties and
methods, which is ready to use
• If the class is derived from a derived class, then it is referred to as Multilevel inheritance
Parent Class
• It’s an existing class;
• The class whose features are inherited
• The parent class is also known as a base class, superclass
Child Class
• It’s an extended class;
• The class that inherits the other class is known as subclass
• The child class is also known as an extended class, derived class, subclass
class PARAM_CLASS #(WIDTH = 5, DEPTH =10) ;
bit[WIDTH-1: 0] data;
bit[DEPTH-1: 0] addr;
function new();
$display("IN new constructor addr = %0d, data = %0d , WIDTH = %0d, SEPTH = %0d", addr,data,WIDTH, DEPTH);
endfunction
function void display();
$display("addr = %0d, data = %0d , WIDTH = %0d, SEPTH = %0d", addr,data,WIDTH, DEPTH);
endfunction
endclass
module tb();
PARAM_CLASS #(8,4) p1;
initial begin
p1 = new();
p1.display();
end
endmodule
class inheritance_class;
function new();
opcode = 4;
endfunction
function display();
endfunction
endclass
bit[10:0] addr;
bit[8: 0] data;
function new();
addr = =10;
data = 15;
endfunction
function print();
$display("I am in sub-class opcode = %0x data = %0x addr = %0x", opcode, data, addr);
endfunction
endclass
module tb();
inheritance_class_sub_Class ch;
inheritance_class pa;
initial begin
ch = new();
pa = new();
pa.display();
ch.print();
end
endmodule.