Barclays interview question

what is the output public class Barclays { static class A{ A(){ f(); } public void f(){ System.out.println("A ctor"); } } static class B extends A{ B(){ f(); } public void f(){ System.out.println("B ctor"); } } public static void main(String[] args) { B b = new B(); b.f(); A a = new A(); a.f(); } }

Interview Answers

Anonymous

19 Dec 2014

The first line is A ctor as the first line of any constructor is super()

5

Anonymous

29 May 2010

B ctor B ctor B ctor A ctor A ctor

4