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

Quiz: static, final and Nested Classes · Question 5 of 10

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

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

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

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

An inner object belongs to one outer object, so you need an outer object to create it.

Can you get the rest right without peeking?

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

Start the quiz →