Polymorphism refers to the ability of a class or object to take on multiple forms. Polymorphism is a key feature of object-oriented programming, and it allows developers to create flexible and reusable code that can be adapted to different situations. There are several types of polymorphism... Method polymorphism: This refers to the ability of a method to take on different forms depending on the context in which it is used. For example, a method may behave differently depending on the type or number of arguments that are passed to it. Overloading: This refers to the ability of a method or function to have multiple definitions with different signatures (i.e., different numbers or types of arguments). Overloading allows developers to create multiple versions of a method or function that can be called depending on the context in which it is used. Inheritance: This refers to the ability of a class to inherit properties and behaviors from a parent class. Inheritance allows developers to create a hierarchy of classes that share common characteristics, and it allows them to create more specialized classes that are derived from more general ones.
// Code your testbench here // or browse Examples //polymorphism class a; virtual function void print(); $display("This is Parent class"); endfunction endclass class b extends a; function void print(); $display("This is child class"); endfunction endclass module main; a a1; b b1;
initial begin a1=new(); b1=new(); a1=b1; a1.print(); b1.print(); end
Helpful, Thank you so much.
It's a beautiful explanation, also crisp and clear.🥰
splendid thanks bro
Detailed explanation very good 👍👍
Thanks a lot
clean and clear explanation
very well explained sir!
Thanks and welcome
Only method we can excess
how polymorphism is used ?
Please complete the system verilog course🥺
Can I get the exact definition of Polymorphism
Polymorphism refers to the ability of a class or object to take on multiple forms. Polymorphism is a key feature of object-oriented programming, and it allows developers to create flexible and reusable code that can be adapted to different situations.
There are several types of polymorphism...
Method polymorphism: This refers to the ability of a method to take on different forms depending on the context in which it is used. For example, a method may behave differently depending on the type or number of arguments that are passed to it.
Overloading: This refers to the ability of a method or function to have multiple definitions with different signatures (i.e., different numbers or types of arguments). Overloading allows developers to create multiple versions of a method or function that can be called depending on the context in which it is used.
Inheritance: This refers to the ability of a class to inherit properties and behaviors from a parent class. Inheritance allows developers to create a hierarchy of classes that share common characteristics, and it allows them to create more specialized classes that are derived from more general ones.
SIRplease provide the code
// Code your testbench here
// or browse Examples
//polymorphism
class a;
virtual function void print();
$display("This is Parent class");
endfunction
endclass
class b extends a;
function void print();
$display("This is child class");
endfunction
endclass
module main;
a a1;
b b1;
initial begin
a1=new();
b1=new();
a1=b1;
a1.print();
b1.print();
end
endmodule