Suppose I have two classes defined the following way:
public class A {
public A() {
foo();
}
public void foo() {
System.out.println("A");
}
}
public class B extends A {
private String bar;
public B() {
bar = "bar";
}
@Override
public void foo() {
System.out.println(bar);
}
}
And then i instantiate B the following way:
A test = new B();
So why can't the compiler respectively the IDE warn me that there will be a NullPointer in the foo method of B? That wouldn't be to difficult to check and sometimes very useful.