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

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

c# - SharpSVN - How to get the previous revision? -

php cli reading files and how to fix it? -