Can anyone explain the output of below code? Trying to extend class A in Class B and overriding method goo() and method foo() is called from the constructor.
public class A {
public A() {
foo();
}
private void foo() { // Private function foo()
System.out.print("A::foo ");
goo();
}
public void goo() {
System.out.print("A::goo ");
}
}
public class B extends A {
public B() {
foo();
}
public void foo() {
System.out.print("B::foo ");
}
public void goo() {
System.out.print("B::goo ");
}
}
public class C {
public static void main(String[] args) {
A b = new B();
}
}
Output : A::foo B::goo B::foo
Thanks.