0% found this document useful (0 votes)
4 views8 pages

parameterize_and_inheritance 1

The document discusses parameterized classes and inheritance in object-oriented programming. Parameterized classes allow for the definition of attributes with default values that can be overridden, while inheritance enables the creation of new classes based on existing ones, allowing for property and method reuse. It includes examples of parameterized class instantiation and subclassing in a programming context.

Uploaded by

Vinay A J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

parameterize_and_inheritance 1

The document discusses parameterized classes and inheritance in object-oriented programming. Parameterized classes allow for the definition of attributes with default values that can be overridden, while inheritance enables the creation of new classes based on existing ones, allowing for property and method reuse. It includes examples of parameterized class instantiation and subclassing in a programming context.

Uploaded by

Vinay A J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Parameterized class &

inheritance
Parameterized Classes

• Parameterized classes are same as the parameterized modules in the


verilog. parameters are like constants local to that particular class.
• The parameter value can be used to define a set of attributes in class.
default values can be overridden by passing a new set of parameters
during instantiation. this is called parameter overriding.
Inheritance

• 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;

bit [3:0] opcode;

function new();

opcode = 4;

endfunction

function display();

$display(" I am in base class opcode = %0x", opcode);

endfunction

endclass

class inheritance_class_sub_Class extends inheritance_class;

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.

You might also like