Why is there a compilation error with the line if (i == 0) { print(); }
? Is it because main is static, even though it is within the class of A?
public class A {
private void print() { System.out.print(foo() + " "); }
public String foo() { return "AAA"; }
public static void main(String[] args) {
A[] arr = { new A(), new B() };
for (int i = 0; i < 2; i++) {
/***/ if (i == 0) { print(); }
}
}
}
public class B extends A {
private void print() { System.out.println("%" + foo() + " "); }
public String foo() { return "BBB"; }
public void bar() { print(); }
}