Regarding Inheritance

M

Mahesh

I have two packages package1 and package2.

Suppose this the code of package1
package package1;

my $file_scope_var = "var in package1"

sub new
{
my $proto = shift;
my $self = { };
my $class = ref ($proto) || $proto;
bless ($self, $class);
$self->{NAME} = undef;
}

sub print_package1
{
my $self = shift;
my $name = $self->NAME();
my $file_scope_var = $self->file_scope_var();
print"\n\n Name is $name and file scope var is $file_scope_var";
}


suppose the code of package2 is
package package2
@ISA=("package1");

sub new
{
my $proto = shift;
my $self = { };
my $class = ref ($proto) || $proto;
}

sub print_package2
{
my $self = shift;
$self->print_package1();
}

now my problem is that since Iam inheriting package1 into package2.
and Iam calling print_package1 in package2.

Will that call to print_package2 will print file_scope_var value or
not. Since it is a file scope variable will it get printed when we call
print_package2 or not.

Please help me in this soon as I was stuck in the middle of the work.
Thanks and Regards,
Mahesh
 
S

Sherm Pendley

Mahesh said:
Will that call to print_package2 will print file_scope_var value or
not. Since it is a file scope variable will it get printed when we call
print_package2 or not.

Have a look at "perldoc perltooc", in the section "Inheritance Concerns"
for a discussion of class variables and inheritance mix.

sherm--
 
S

Sherm Pendley

Mahesh wrote:

.... twice. Please don't do that. We heard you the first time.

sherm--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top