#
A virtual class is a temple or place holder for the child classes. A virtual class is also called as the abstract class. A virtual class is declared with a virtual keyword like :
virtual class base;
endclass;
A virtual class instance or object can not be constucted but you can define the hadle to the virtual class.
Virtual methods can be defined as templates. Basically it forces all extended classes to implement the functions. In the virtual functions
- First and the last line of the subprgrams only is defined
- Defines name and the arguments
- Does not define the implementation or virtual functions does not have a body.
- For virtual functions a implementation must be defined by the extened subclasses basically it forces them to implement standard set of methods
- Virtual method templates are basically defined in the virtual classes.
01.
virtual
class
baseframe;
02.
...
03.
virtual
function
void
iam();
04.
endfunction
05.
...
06.
endclass
07.
08.
class
shortframe
extends
baseframe;
09.
...
10.
function
void
iam();
11.
$display (
"Short Frame"
);
12.
endfunction
13.
endclass
14.
15.
class
longframe
extends
baseframe;
16.
...
17.
function
void
iam();
18.
$display (
"Long Frame"
);
19.
endfunction
20.
endclass
21.
22.
baseframe two;
// OK
23.
24.
initial
begin
25.
two =
new
(4);
// ERROR
26.
...