Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7808739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:13:10+00:00 2026-06-02T03:13:10+00:00

New to OOP perl…First program, not bale to overload constructor. I have tried many

  • 0

New to OOP perl…First program, not bale to overload constructor. I have tried many things, may be I’m still missing few things !

Base class:

#!/usr/bin/perl
use strict;
package Person;
sub new
{
my($class)=shift;
my($self)={ 
        _name=>shift,
        _sname=>shift,
};
bless $self, $class;
return $self;
}       
1;  

Derived class:

#!/usr/bin/perl
package Employee;
use strict;
use Person;
our @ISA = qw(Person);
sub new
{
my($class)=@_;
my($self)=$class->SUPER::new($_[1],$_[2]);
my $self1={
        _id=>$_[3],
        _sal=>$_[4],
};
bless $self1,$class;
return ($self);
}
1;

Main Program:

#!/usr/bin/perl
use strict;
use Data::Dumper;
use Employee;

sub main
{
my($obj)=Employee->new("abc","def","515","10");
print Dumper $obj;
}
main();

I’m not able to get values of base class class members. Not getting what i miss in the program. Help me out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:13:11+00:00Added an answer on June 2, 2026 at 3:13 am

    There’s no need for an object called $self1 in your derived constructor. You should just say:

    sub new {
        my($class)=@_;
        my($self)=$class->SUPER::new($_[1],$_[2]);
        $self->{_id} = $_[3];
        $self->{_sal} = $_[4];
        # no need to bless -- $self is already blessed correctly in SUPER::new
        return ($self);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to OOP, and in the program I'm working on, I have
New to OOP with Perl, and just had a quick question. I have this
I'm relatively new to OOP, so wanted to clear a few things, I have
I'm new to programming and some OOP concepts and am not sure what is
I'm new to Java, but have some OOP experience with ActionScript 3, so I'm
I'm really new to OOP. I'm even not a newbie - I'm noob. So.
I'm very new to OOP and am trying my hardest to keep things strictly
I'm pretty new in OOP but have to develop a big project... Just for
Ok this may be a noobolicious question as im new to OOP. Im attempting
I am pretty new to OOP with PHP. OK first of all this produces

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.