Apologies if this has been posted before, I keep only getting results for overriding the opposite way.
I want to be able to do 2 things:
- Reference the parent variable from the child class, in assigning the value for the child variable.
- Have the method in the adult class that references this variable use the child classes value. That way, I can have a lot of child classes, but not have the same repeating code for the method.
Here's a super simple pseudo-example of what I mean:
child class:
public class ChildClass extends AdultClass {
static int a=super.a+1;
}
adult class:
public class AdultClass {
static int a=5;
static public int getA() {
return a;
}
}
class that uses ChildClass object:
public class ClientClass {
public static void main(String[] args) {
ChildClass.a <-I want this to =6
ChildClass.getA() <-I want this to return 6
}
}