in reply to Class Methods
package A; sub foo { print "this is from class A\n"; } package B; use base 'A'; sub foo { print "this is from class B\n"; } sub bar { print "this is from class B, too\n"; } package C; use base 'A'; sub bar { print "Finally, this is from class C.\n"; }
In this example, package C inherits the foo method from package A, because it is declared a subclass with use base and does not define its own method foo. Package B, on the other hand, defines its own foo method, which overrides the parent class.
See perlboot and perltoot for more information about doing OOP in Perl.
|
|---|