I have the following code: The constructor of class A calls an abstract method implemented by class B which returns a variable from class B. This variable will be null by the time A calls the abstract method even if I instantiated it in the declaration. Is there any way I can instantiate it this way?
public abstract class A { public A() { isStringNull(); } protected abstract String getMyString(); private void isStringNull () { if (getMyString() == null) { System.out.println("String is null :("); } else { System.out.println(getMyString()); } } } public class B extends A { private String amINull = "Of course not"; @Override protected String getMyString() { return amINull; } } public static void main(String[] args) { new B(); } Can somebody please explain why the string will be null?