Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.

A() called
B() called
A version of foo1() called

b.

A() called
B() called
A version of foo1() called
B version of foo1() called

c.

A() called
B() called
B version of foo1() called

d.

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.

-------------------------------------------------------------------------------------------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote