A() called B() called A version of foo1() called A() called B() called A version
ID: 3570680 • Letter: A
Question
A() called
B() called
A version of foo1() called
A() called
B() called
A version of foo1() called
B version of foo1() called
A() called
B() called
B version of foo1() called
A() called
B() called
B version of foo1() called
A version of foo1() called
A() called
B() called
A version of foo1() called
A() called
B() called
A version of foo1() called
B version of foo1() called
A() called
B() called
B version of foo1() called
A() called
B() called
B version of foo1() called
A version of foo1() called
Explanation / Answer
The Correct option is (c)
A() called
B() called
B version of foo1() called
Reason:
statement B b2 = new B(); creates new instance of class B.
When an object is created, first the constructor is invoked.
The 1st statement of B's constructor invokes A's Constructor.
Hence
A() called
After the statement in B's constructor is printed.
B() called is printed.
Later B's foo1() method is invoked.
-------------------------------------------------------------------------------------------------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.