Re: [General]acces of members of subclass
- From: RedGrittyBrick <RedGrittyBrick@xxxxxxxxxxxxx>
- Date: Sun, 27 Jul 2008 10:12:30 +0100
Daniel Moyne wrote:
When you have this :
public class My_Class {
public method_1 {...}
public method_2 {...}
public int u;
public String v;
}
you can get access to members like this :
My_Class aa=new My_Class();
int k=aa.u;
String l=aa.v;
but in this case :
public class My_Class {
public method_1 {...}
public method_2 {...}
public int u;
public String v;
}
public class My_Other_Class extends My_Class{
public method_3 {}
public method_4 {}
public int w;
public String z;
}
How can I access public members w and z once I have done this :
My_Class aa=new My_Other_Class();
You can't do it in a clean way.
if (aa instanceof My_Other_Class)
((My_Other_Class)aa).w = 2;
Works but is nasty. If you need to access w then you should declare aa as being of type My_Other_Class.
Apparently subclasses are designed for private members ?
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).
--
RGB
.
- Follow-Ups:
- References:
- [General]acces of members of subclass
- From: Daniel Moyne
- [General]acces of members of subclass
- Prev by Date: Rifle & Ammunition Retail Store - Sportsman, Wildlife and Outdoor Supply
- Next by Date: Re: [NetBeans]changing menuitems
- Previous by thread: [General]acces of members of subclass
- Next by thread: Re: [General]acces of members of subclass
- Index(es):
Relevant Pages
|