Saturday, July 9, 2011

inheritance example 2

Perl Script:

#usr/bin/perl
package Person;
sub new
{
my $pkg=shift;
bless{ @_ },$pkg;
}
package Student;
@ISA=qw(Person);
$ddd=new Person(name=>"jjjjj",age=>55);
$aaa=new Student(name=>'ssss',id=>55,class=>"tenth");
print $ddd->{name};
print $aaa->{name};

Output:

jjjjj
ssss

No comments:

Post a Comment