The output of the program is A isn't it suppose to be B. If I change the modifier of method in Class A to public then the output is B. Can somebody explain what is going on here?
Code:
public class HelloWorld {
public static void main(String[] args) {
HelloWorld hw = new HelloWorld();
hw.createInstance();
}
public void createInstance() {
A b = new B();
b.isTrue();
}
public class A {
private void isTrue() {
System.out.println("A");
}
}
public class B extends A {
public void isTrue() {
System.out.println("B");
}
}
}
Output: A