Assuming var is private, and you need to set the value using a constructor (which seems to be the point of the question, otherwise there are many simple solutions), I would just do it with a static factory method.
class B extends A { int var2; public static B createB(int x, int y) { x = f(y); return new B(x, y); } public B(x, y) { super(x); this.var2 = y; } }
something like that. You have no choice, since an explicit constructor call should occur on the first line of the wrapper constructor.
source share