Re: [General]acces of members of subclass



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
.



Relevant Pages

  • Re: Arrays
    ... >public class collect{ ... > public int Limit; ... > public void setRegistrationNumber{ ... > public String getRegistrationNumber() { ...
    (comp.lang.java.help)
  • [General]acces of members of subclass
    ... public class My_Class { ... How can I access public members w and z once I have done this: ...
    (comp.lang.java.help)
  • Re: NullReferenceException when passing structures by reference to a C API
    ... to isolate the problem you may comment out some members of ADMIN_PROF struct ... public struct ADMIN_PROF ... public String login_name; ... public int warning_flag; ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Arrays
    ... public class collect{ ... public int Limit; ... public void setRegistrationNumber{ ... public String getRegistrationNumber() { ...
    (comp.lang.java.help)
  • Re: Need Help Stepping Through Deserialized Object
    ... foreach (DataRow row in dt.Rows) ... public class Category { ... public string model ... public int jsonkey ...
    (microsoft.public.dotnet.languages.csharp)