Sunday, July 10, 2011

Callig parent method from child class


Perl Script:


package Inventory_item;
sub new {
$class=shift;
%params=@_;
bless {
"PART_NUM" => $params{"hh"},
"PART_VAL" => $params{"qq"}
},$class;
}
package Coloritem;
@ISA=("Inventory_item");
@PARENT::ISA=@ISA;  # this is the statement needed for calling parent method from child class
sub new {
my($class)=shift;
my(%params)=@_;
my($self)=$class->PARENT::new(@_);
$self->{"INK_COLOR"}=$params{"INK_COLOR"};
return($self);
}
package main;
$item=Coloritem->new("hh","22222","qq","3232323232","INK_COLOR","54545555");
print("The part num is ".$item->{'PART_NUM'} ."\n");
print ("The quantity is ".$item->{'PART_VAL'} ."\n");
print ("the  ".$item->{'INK_COLOR'}."\n");


OUTPUT:


G:\perl_programs>perl perl_parent.pl
The part num is 22222
The quantity is 3232323232
the  54545555
G:\perl_programs>

No comments:

Post a Comment