B
bfeist
I want to have a static constant X defined in a superclass A and given
various different values in subclasses B, C, and so on. When the X is
accessed in a method of A by class B (through inheritance), I want it
to get the value of B.X, not A.X. Is this possible?
My initial naive attempt at just defining X separately in each class as
a static final did not work; A.X is accessed instead. Unless someone
has a better idea, I'll resort to replacing the constant by a static
method returning the desired constant instead, and rely on
polymorphism.
Any ideas? Thanks in advance.
various different values in subclasses B, C, and so on. When the X is
accessed in a method of A by class B (through inheritance), I want it
to get the value of B.X, not A.X. Is this possible?
My initial naive attempt at just defining X separately in each class as
a static final did not work; A.X is accessed instead. Unless someone
has a better idea, I'll resort to replacing the constant by a static
method returning the desired constant instead, and rely on
polymorphism.
Any ideas? Thanks in advance.