🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Nested and Anonymous Classes: all 10 questions

Quiz: Nested and Anonymous Classes · Question 2 of 10

How do you create an object of the inner (non-static) class Account inside Bank?

How do you create an object of the inner (non-static) class Account inside Bank?

  1. A.new Bank.Account(500)
  2. B.Bank.new Account(500)
  3. C.bank.new Account(500) where bank is a Bank object
  4. D.new Account(bank, 500) is the only way
Answer & explanation

Correct answer: bank.new Account(500) where bank is a Bank object

Each inner object must be linked to an outer object, so you create it through one.

Can you get the rest right without peeking?

Take the timed Quiz: Nested and Anonymous Classes quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →