Yoda
Yoda

Reputation: 18068

How to get overriden value of final static field in superclass' method?

I have a

class A{ public final static String S = "A"
 public void getS(){return S;}
}
class B extends A {public final static String S "B"}

Is it possible by reflection or something like that to return by getS()method value "B" instead of "A" without overriding it in subclasses in that situation:

B b = new B();
b.gets(); // I would like RESULT "B"

Upvotes: 0

Views: 36

Answers (1)

ivanorone
ivanorone

Reputation: 449

Why don't you override getS() in B?

If you do, then you will be able to get B instead of A.

Upvotes: 1

Related Questions