public class Bar {
private Foo m_foo;
private int getNumbers(){
m_foo=new Foo();
return 5;
}
public void test1(){
m_foo.print(getNumbers());
}
}
public class Foo {
public void print(int x){
System.out.println(x);
}
}
public class Main {
public static void main(String args[]){
new Bar().test1();
}
}
The NullPointerException occurs in test1()
call, but I can't understand the reason behind. Isn't the m_foo
supposed to be instantiated in the getNumbers()
which should get evaluated first?