C
cjburkha
I'm new to Java, so excuse if this is in the wrong group, or off base.
I have two classees
I want to have a base class with a member and method that will be
available to all sub classes. I also want an external method that can
utilize that base class method on all sub classes. I want to write a
method that can use getName on all subclasses so I can write this
method only once. To use the method in the function body, I need the
<base> call, but that disallows me from passing <subBase> to the
method.
Does this make sense? I tried to keep the explanation generic, but
might have made it too confusing. IF so, I will try and re-wright this.
Thanks for your time
I have two classees
Code:
public class Base {
protected Long id;
protected String name;
....
public Strin getName() {
return this.name;
}
}
public class subBase extends Base {
...
public someOtherMethod() {
}
}
In my code I have this:
ArrayList<subBase> multipleInstance = new ArrayList<subBase>();
multipleInstance = fillSubBase();
public void manipulateArray(ArrayList<Base> arrayToManipulate) {
//This is what I want, but it is wrong
arrayToManipulate.get(0).getName();
}
available to all sub classes. I also want an external method that can
utilize that base class method on all sub classes. I want to write a
method that can use getName on all subclasses so I can write this
method only once. To use the method in the function body, I need the
<base> call, but that disallows me from passing <subBase> to the
method.
Does this make sense? I tried to keep the explanation generic, but
might have made it too confusing. IF so, I will try and re-wright this.
Thanks for your time