Re: [General]acces of members of subclass
- From: Lew <com.lewscanon@lew>
- Date: Sun, 27 Jul 2008 09:49:09 -0400
Daniel Moyne wrote:
Apparently subclasses are designed for private members ? [sic]
RedGrittyBrick wrote:
I'm sorry I've no idea what you mean by this. You can have subclasses which declare additional public fields (I find your "member" terminology a little confusing).
Daniel was mistaken. Subclasses are not "designed for private members".
Changing the examples, since "My_Class" violates the naming convention by having an underscore and having "Class" as a class name part is silly,
public class Super
{
public void foo() { ... }
}
public class Sub extends Super
{
public void bar() { ... }
}
later:
Super sup = new Sub();
This has no difficulty - perfectly legal, with public members and all. However:
sup.bar();
is illegal, not because 'bar()' is public, but because 'bar()' is not declared for type 'Super'. The variable 'sup' is of type 'Super', therefore cannot access anything but members of 'Super'.
So, Daniel, the correct explanation is that superclasses are not "designed" to access subclass members, irrespective of accessibility. Superclass variables can access only superclass members.
That is a compile-time rule. The run-time dispatch through the superclass member to overridden subclass functionality is a separate matter.
--
Lew
.
- Follow-Ups:
- Re: [General]acces of members of subclass
- From: Daniel Moyne
- Re: [General]acces of members of subclass
- References:
- [General]acces of members of subclass
- From: Daniel Moyne
- Re: [General]acces of members of subclass
- From: RedGrittyBrick
- [General]acces of members of subclass
- Prev by Date: Re: Text in if condition is not displayed in the browser
- Next by Date: Re: [NetBeans]changing menuitems
- Previous by thread: Re: [General]acces of members of subclass
- Next by thread: Re: [General]acces of members of subclass
- Index(es):
Relevant Pages
|