constructor - Java: Final variables in abstract classes -
in java, can't create instances of abstract classes. why doesn't eclipse scream following code?
public abstract class footype { private final int myvar; public footype() { myvar = 1; } }
the code fine, final variable initialized in constructor of footype
.
you cannot instantiate footype
because of being abstract. if create non abstract subclass of footype
, constructor called.
if not have explicit call super(...)
in constructor, java compiler add automatically. therefore ensured constructor of every class in inheritance chain called.
Comments
Post a Comment