Okay, why is the subclass's new() not required? Is it because the DBLogon's additional field (DBNAME) is added via the _init() method? So you end up with something like this:
# Base class Logon new() sub new { my $that = shift; my $class = ref($that) || $that; my $self = {}; bless $self, $class; $self->_init(); return $self; } # Base class Logon _init() sub _init { my $self = shift; $self->{USERID} = undef; $self->{SERVER} = undef; } Then the subclass DBLogon would no longer have a new() method, but would retain its _init() method, which would be modified to call the SUPER's _init as well, right? # Subclass DBLogon init() sub _init { my $self = shift; $self->SUPER::_init(); $self->{DBNAME} = undef; } Just to clarify, the only reason I don't need a new() method in the subclass is because any class-specific logic is contained in the _init() method for both parent and subclass. If there were no _init() method, then both classes would have a new(), right? -----Original Message----- From: Bob Showalter [mailto:[EMAIL PROTECTED] Sent: Friday, April 01, 2005 10:44 AM To: '[EMAIL PROTECTED]'; beginners@perl.org Subject: RE: Attempting OO with Perl - New() method in subclass not working [EMAIL PROTECTED] wrote: > I am trying to build an inheritable object, and I am using examples > from the Perl Cookbook, 2nd edition, mostly Recipe 13.1, using the new > and _init methods. Your subclass does not need (and should not have) a new() method; it can use the one from the base class. As Randal pointed out, the subclass _init needs to call $self->SUPER::_init(), and then do any additional initialization. If there is no additional initialization in the subclass, you don't need an _init method there either. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>