I wrote this piece of code:
class A {
public A() {
someMeth();
}
public void someMeth() {
out.println(entries[0]);
}
public final String[] entries = { "a" };
}
class B extends A {
public void someMeth() {
out.println(entries[0]); *** NullPTR
super.someMeth();
}
private final String[] entries = { "b" };
}
the point is to start, during instantiation, some methods from the
bottom of the inheritance tree instead of from the top.
but i had some unexpected behavior: at the marked point, I receive a
NullPTR.
Why does this happen?
Seem like that at the moment of the call (***) member vars are not
instantiated, since the call comes from the constructor of the
superclass, and the subclass is not still instantiated, but why then the
subclass method works?
Bye!
it