pkoti83
Newbie level 5
- Joined
- Oct 22, 2013
- Messages
- 10
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 94
Can you please correct me , if the details which i have mentioned below are wrong
EXAMPLE: without virtual
class A ;
task disp ();
$display(" This is class A ");
endtask
endclass
class B extends A ;
task disp ();
$display(" This is Extended class A ");
endtask
endclass
program main ;
B B1; //Handle B1 is declared for an object B
A A1; //Handle A1 is declared for an object A
initial
begin
A1 = new(); //1)object will be created 2) construct the object 3) Assign the address of an object A to A1.
A1.disp(); // call the disp() task of parent class
B1 = new(); //1)object will be created 2) construct the object 3) Assign the address of an object B to B1.
A1 = B1; // assigning B1 pointer to A1 i.e Both A1 and B1 Pointing to same object
(1) My question in this case is an object A with out handle leads to deallocation of an object A then
if you call A1.disp() task how it will give result as "This is class A"
2) how we can call a parent class method with out an object A
A1.disp();
end
endprogram
RESULTS
This is class A
This is class A (It should not be displayed because there is no Object A i.e Object A handle is assigned to Object B by using this equation A1 = B1, it indicates that Object A is deallocated)
EXAMPLE: without virtual
class A ;
task disp ();
$display(" This is class A ");
endtask
endclass
class B extends A ;
task disp ();
$display(" This is Extended class A ");
endtask
endclass
program main ;
B B1; //Handle B1 is declared for an object B
A A1; //Handle A1 is declared for an object A
initial
begin
A1 = new(); //1)object will be created 2) construct the object 3) Assign the address of an object A to A1.
A1.disp(); // call the disp() task of parent class
B1 = new(); //1)object will be created 2) construct the object 3) Assign the address of an object B to B1.
A1 = B1; // assigning B1 pointer to A1 i.e Both A1 and B1 Pointing to same object
(1) My question in this case is an object A with out handle leads to deallocation of an object A then
if you call A1.disp() task how it will give result as "This is class A"
2) how we can call a parent class method with out an object A
A1.disp();
end
endprogram
RESULTS
This is class A
This is class A (It should not be displayed because there is no Object A i.e Object A handle is assigned to Object B by using this equation A1 = B1, it indicates that Object A is deallocated)