- or download this
# file P1.pm
package P1;
...
sub A1 { print "i am A1 in P1\n"; }
sub A2 { print "i am A2 in P1\n"; }
1;
- or download this
# file P2.pm
package P2;
...
sub A1 { print "i am A1 in >>>P2<<< (i have overwritten previous A1)\n
+"; }
# A2 and everything else are inherited from class P1
1;
- or download this
# file test.pl
# run: perl -I. test.pl
...
$P2obj->A1(); # this is overwritten
$P2obj->A2(); # this is inherited verbatim from parent P1