Important Java Mcq 1

Can inner classes be reused?

a. True

b. False

c. True in some cases

Answer:

c. True in some cases

Explanation

Regular inner class holds a reference to an object of the outer class, so its instance cannot be created without the outer class. It means that inner classes cannot be re-used from outside the outer class. Anonymous inner classes you are using cannot be reused for sure: they are created in the context of the outer method. You can however define inner class as static. In this case, you can use it from everywhere in your code.

Related MCQs

A java exception is an instance of

a. RuntimeException b. Exception c. Error d. Throwable e. NumberFormatException Answer: d. Throwable Explanation: Every exception is represented by an instance of the class Throwable.

Aniket Malik

Aniket Malik

CERTIFIED TUTOR/TRAINER WITH 300+ REVIEWS

Facing difficulty with

this concept?