What is the use of the abstract class?

Companies Related Questions, System Verilog 0 Comments

With inheritance we are able to force a subclass to offer the same properties like their superclasses. Consequently, objects of a subclass behave like objects of their superclasses.

Sometimes it make sense to only describe the properties of a set of objects without knowing the actual behaviour beforehand

Abstract classes are those which can be used for creation of handles. However their methods and constructors can be used by the child or extended class. The need for abstract classes is that you can generalize the super class from which child classes can share its methods. The subclass of an abstract class which can create an object is called as “concrete class”.

 

EXAMPLE:

using abstract class

virtual class A ;
virtual task disp ();
$display(” This is class A “);
endtask
endclass

class EA extends A ;
task disp ();
$display(” This is Extended class A “);
endtask
endclass

program main ;
EA my_ea;
A my_a;

initial
begin
my_ea = new();
my_a = my_ea;
my_ea.disp();
my_a.disp();
end
endprogram

RESULT

This is Extended class A
This is Extended class A

EXAMPLE: creating object of virtual class
virtual class A ;
virtual task disp ();
$display(” This is class A “);
endtask
endclass

program main ;
A my_a;

initial
begin
my_a = new();
my_a.disp();
end
endprogram

RESULT

Abstract class A cannot be instantiated
Virtual keyword is used to express the fact that derived classes must redefine the properties to fulfill the desired functionality. Thus from the abstract class point of view, the properties are only specified but not fully defined. The full definition including the semantics of the properties must be provided by derived classes.

Definition (Abstract Class) A class A is called abstract class if it is only used as a superclass for other classes. Class A only specifies properties. It is not used to create objects. Derived classes must define the properties of A.

Leave a Reply