1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | use Person; package Employee; @ISA = qw (Person); sub new { shift; my ($name, $age, $salary) = @_; my $self = Person->new ($name, $age); $self->{salary} = $salary; bless ($self); return $self; } sub change_salary { my $self = shift; my $new_salary = shift; $self->{salary} = $new_salary; } my $object_employee = Employee->new ( "Tonny", 28, 10000 ); print "Name : " . $object_employee->{name} . ", Age : " . $object_employee->{age} . ", Salary : " . $object_employee->{salary} . ". \n"; $object_employee->change_name ("Tommy"); $object_employee->change_salary (13000); print "Name : " . $object_employee->{name} . ", Age : " . $object_employee->{age} . ", Salary : " . $object_employee->{salary} . ". \n"; |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |