- #1
walnutTree
- 5
- 0
Hi All,
Sorry to bother anyone, but I have run into a inheritance problem.
I have a base class which contains a member variable of array type, and an abstract method. Subsequently I created a sub class which derived from the base class. And I provide implementation for the abstract methods in the parent class. And I would like to override my array variable in the sub class, and use it as return value of .
Is there any way to able to override my variable?
here is my base class
and the following code contains the sub class with the main function:
Sorry to bother anyone, but I have run into a inheritance problem.
I have a base class which contains a member variable of array type, and an abstract method. Subsequently I created a sub class which derived from the base class. And I provide implementation for the abstract methods in the parent class. And I would like to override my array variable in the sub class, and use it as return value of .
Is there any way to able to override my variable?
here is my base class
Code:
public abstract class Parent{
String[] labels;
public Parent()
{
getLabels();
}
public abstract String[] getLabels();
}
and the following code contains the sub class with the main function:
Code:
public class Child extends Parent{
String[] labels ={"name", "nickname", "birth"};
public String[] getLabels()
{
System.out.println("labels: " + labels);
return labels;
}
public static void main(String[] args)
{
new Child();
}
}