New to OOP perl ... The first program, not a bale to overload the constructor. I tried a lot of things, maybe I'm still missing a few things!
Base class:
use strict;
package Person;
sub new
{
my($class)=shift;
my($self)={
_name=>shift,
_sname=>shift,
};
bless $self, $class;
return $self;
}
1;
Derived class:
package Employee;
use strict;
use Person;
our @ISA = qw(Person);
sub new
{
my($class)=@_;
my($self)=$class->SUPER::new($_[1],$_[2]);
my $self1={
_id=>$_[3],
_sal=>$_[4],
};
bless $self1,$class;
return ($self);
}
1;
The main program:
use strict;
use Data::Dumper;
use Employee;
sub main
{
my($obj)=Employee->new("abc","def","515","10");
print Dumper $obj;
}
main();
I cannot get the values of the members of a base class class. Do not get what I missed in the program. Help me.
source
share