Question about access and visibility

Discussion in 'Java' started by Mark, Sep 20, 2004.

  1. Mark

    Mark Guest

    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?
     
    Mark, Sep 20, 2004
    #1
    1. Advertising

  2. Mark wrote:
    > 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?
     
    Michael Borgwardt, Sep 21, 2004
    #2
    1. Advertising

  3. Mark

    Jacob Guest

    Mark wrote:

    > 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).
     
    Jacob, Sep 21, 2004
    #3
  4. Mark

    Mark F Guest

    Jacob wrote:
    > Mark wrote:
    >
    >> 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).
    >
    >


    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
     
    Mark F, Sep 21, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BG

    Class Visibility Question

    BG, Jan 23, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    296
    Daniel Fisher\(lennybacon\)
    Jan 30, 2005
  2. Casper Bang
    Replies:
    51
    Views:
    1,214
  3. randy.buchholz

    Nub Question - Details View Visibility

    randy.buchholz, Jan 7, 2008, in forum: ASP .Net
    Replies:
    4
    Views:
    321
    randy.buchholz
    Jan 8, 2008
  4. Seth Williams

    Menu/SiteMap question - visibility

    Seth Williams, May 7, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    305
    Cowboy \(Gregory A. Beamer\)
    May 7, 2008
  5. Harpo
    Replies:
    2
    Views:
    100
    Harpo
    Feb 7, 2004
Loading...

Share This Page