0% found this document useful (0 votes)
93 views4 pages

VSDV

The document defines a class hierarchy for counting objects. The Parent class defines a count variable and counter task. Child classes extend Parent and override the counter task to increment/decrement count. Grandchild classes extend the child classes and iterate the counter task in a for loop. The main program instantiates the classes and calls their counter tasks to increment/decrement counts as specified in the class hierarchy.

Uploaded by

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

VSDV

The document defines a class hierarchy for counting objects. The Parent class defines a count variable and counter task. Child classes extend Parent and override the counter task to increment/decrement count. Grandchild classes extend the child classes and iterate the counter task in a for loop. The main program instantiates the classes and calls their counter tasks to increment/decrement counts as specified in the class hierarchy.

Uploaded by

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

class Parent;

integer count;
function new();
count=0;
endfunction
task counter();
$display("count value is %d",count);
endtask
endclass
class child1 extends Parent;
task counter();
count=count+1;
super.counter();
endtask
endclass
class child2 extends Parent;
task counter();
super.counter();
count=count-1;
endtask
endclass
class subchild1 extends child1;
integer offset,i;
function new();
offset=8;
endfunction
task counter();
for(i=0;i<offset;i++)
super.counter();
endtask
endclass
class subchild2 extends child2;
integer offset,i;
function new();
offset=8;
endfunction
task counter();
for(i=0;i<offset;i++)
super.counter();
endtask
endclass
program main;
Parent p;
child1 c1;
child2 c2;

subchild1 sc1;
subchild2 sc2;
initial
begin
p=new;
c1=new;
c2=new;
while(c1.count<15)
c1.counter();
$display("---------------------------");
c2.count=c1.count;
while(c2.count>0)
c2.counter();
$display("---------------------------");
sc1=new;
sc1.counter();
sc2=new;
sc2.count=sc1.count;
sc2.counter();
end
endprogram

// Code your design here


class Parent;
integer count,count1;
function new();
count=0;
count1=15;
endfunction
task counter();
$display("count value is %d",count);
endtask
task counter1();
$display("count value is %d",count1);
endtask
endclass
class child1 extends Parent;
task counter();
count=count+1;
super.counter();
endtask
endclass
class child2 extends Parent;
task counter1();
super.counter1();
count1=count1-1;
endtask
endclass
class subchild1 extends child1;
integer offset,i;
function new();
offset=8;
endfunction
task counter();
for(i=0;i<=offset;i++)
super.counter();
endtask
endclass
class subchild2 extends child2;
integer offset,i;
function new();
offset=8;
endfunction
task counter1();
for(i=0;i<=offset;i++)
super.counter1();

endtask
endclass
program main;
Parent p;
child1 c1;
child2 c2;
subchild1 sc1;
subchild2 sc2;
initial
begin
p=new;
c1=new;
c2=new;
while(c1.count<15)
c1.counter();
$display("---------------------------");
while(c2.count1>0)
c2.counter1();
$display("---------------------------");
sc1=new;
sc1.counter();
sc2=new;
sc2.counter1();
end
endprogram

You might also like