As we have already seen in the previous topics , a virtual method may or may not be overridden in the derived lasses. It means, it is not necessary for a derived class to override a virtual method.
But there are times when a base class is not able to define anything meaningful for the virtual method in that case every derived class must provide its own definition of the that method.
A pure virtual method is a virtual method that you want to force derived classes to override. If a class has any unoverridden pure virtuals, it is an "abstract class" and you can't create objects of that type.
" pure virtual function " or " pure virtual task " declaration is supposed to represent the fact that the method has no implementation.
There are two major differences between a virtual and a pure virtual function, these are below:
There CAN'T be a definition of the pure virtual function in the base class.
There MUST be a definition of the pure virtual function in the derived class.
EXAMPLE: class Base;
purevirtualtask disp();
endclass
program main
initial begin Base B;
B = new();
B.disp();
end endprogram
RESULT
Error: pure virtual task disp(); must be overridden in derived class