Question about access and visibility

M

Mark

OK.

Class Alpha is an abstract base class with package level visibiltiy
and a protected method: protectedMethodAlpha

Class Gamma is a concrete class which inherits from Alpha and
overrides (actually defines) the protected method. It is contained
within the same directory as Alpha

Class Delta is a concrete class which inherits from class Gamma and is
in a different package and has public visibility.

Should class Delta be able to override protectedMethodAlpha?
 
M

Michael Borgwardt

Mark said:
Class Alpha is an abstract base class with package level visibiltiy
and a protected method: protectedMethodAlpha

Class Gamma is a concrete class which inherits from Alpha and
overrides (actually defines) the protected method. It is contained
within the same directory as Alpha

Class Delta is a concrete class which inherits from class Gamma and is
in a different package and has public visibility.

Should class Delta be able to override protectedMethodAlpha?

Since it's a subclass of Alpha, why not?
 
J

Jacob

Mark said:
Class Alpha is an abstract base class with package level visibiltiy
and a protected method: protectedMethodAlpha

Class Gamma is a concrete class which inherits from Alpha and
overrides (actually defines) the protected method. It is contained
within the same directory as Alpha

Class Delta is a concrete class which inherits from class Gamma and is
in a different package and has public visibility.

Should class Delta be able to override protectedMethodAlpha?

Yes.

In the discussion, Alpha and Gammas relation to Alpha
is irrelevant. For Delta the interface of Gamma is the
only thing that matters.

Gamma must be public for Delta to extend it from outside
its package. Then Delta can override all of Gammas public
and protected members (including protectedMethodAlpha).
 
M

Mark F

Jacob said:
Yes.

In the discussion, Alpha and Gammas relation to Alpha
is irrelevant. For Delta the interface of Gamma is the
only thing that matters.

Gamma must be public for Delta to extend it from outside
its package. Then Delta can override all of Gammas public
and protected members (including protectedMethodAlpha).

For some reason when I try to create a project that illustrates this
Class Delta cannot find class Gamma, and I get an error line (red
squiggly line) under "..extends Gamma"

-Mark
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top