package X;
sub foo;
sub bar;
package Y;
@ISA = 'X';
sub foo;
package main;
X->foo; # calls X::foo('X');
X->bar; # calls X::bar('X');
Y->foo; # calls Y::foo('Y');
Y->bar; # calls X::bar('Y');
####
// yes, this is C++, so shoot me
class X {
public:
virtual int foo () { return 1; }
int bar () { return 2; }
};
class Y : public X {
virtual int foo () { return 3; }
};
####
void printStuff (X& obj);
####
package Employee;
sub new {
my ($class,$fname,$lname) = @_;
die if $class eq 'Employee';
bless { FNAME => $fname, LNAME => $lname }, $class;
}
package Employee::Boss;
@ISA = qw( Employee );
sub new {
my ($class,$fname,$lname) = @_;
my $self = $class->SUPER::new($fname,$lname);
$self->{PAY} = 1_000_000;
bless $self, $class;
}
# and so on...
####
use Employee;
# defines Employee, Employee::Boss,
# Employee::Hourly, and Employee::Intern
$joe = Employee::Intern->new('Joe', 'Schmoe');
$jay = Employee::Boss->new('Jay','Schmay');
$not = Employee->new('Not', 'Happening'); # <-- dies