I am trying to use a member variable called value in a subclass.
My super class is called SType and my subclass is called SResource.
I have a variable in the super class SType called value
I want this to be inherited by the subclass, how do I do this. The class looks like this
public class SType {
private String value;
public String getValue(){
return this.value;
}
public void setValue(String value){
this.value = value;
}
}
NOTE: I edited the question to make it more clear (given the comment below). Thanks it was a simple solution, just had to make the variable protected rather than `private
In order to access a superclass variable in a subclass, it has to be declared public or protected in the super class.
Maybe yours is private?
When you had
private String valuein the child class – this is a completely new variable – it’s not the one from the parent class i.e. you have two distinct private variables (I am assuming the superclass one is private).