#!/usr/bin/perl package MySubClass; use MyClass; use strict; our @ISA = qw(MyClass); # inherits from MyClass # Override constructor sub new { my ($class) = @_; # Call the constructor of the parent class, Person. my $self = $class->SUPER::new( $_[1] ); # Add few more attributes $self->{_arg2} = $_[2]; bless $self, $class; return $self; } # Override helper function sub getarg1 { my( $self ) = @_; # This is child class function. return $self->{_arg1}; } # Add more methods sub setarg2{ my ( $self, $arg2 ) = @_; $self->{_arg2} = $arg2 if defined($arg2); return $self->{_arg2}; } sub getarg2 { my( $self ) = @_; return $self->{_arg2}; } 1; #my $obj1 = new MyClass "obj1"; #my $obj2 = MySubClass->new("obj2_1","obj2_2"); #print "a1:" . $obj1->getarg1() . "\n"; #$obj1->setarg1("arg1"); #print "a2:" . $obj1->getarg1() . "\n"; #print "b1:" . $obj2->getarg1() . "\n"; #$obj2->setarg1("arg1"); #print "b2:" . $obj2->getarg1() . "\n"; #print "b3:" . $obj2->getarg2() . "\n"; #$obj2->setarg2("arg2"); #print "b4:" . $obj2->getarg2() . "\n";