Inner Classes
1.Which type of inner class can be instantiated without an instance of its outer class?
-
A. Member inner class
-
B. Local inner class
-
C. Anonymous inner class
-
D. Static nested class
Static nested class
Static nested class
2.A non-static member inner class has access to:
-
A. Only static members of the outer class.
-
B. Only private members of the outer class.
-
C. All members (static and non-static, including private) of the outer class.
-
D. Only public members of the outer class.
All members (static and non-static, including private) of the outer class.
All members (static and non-static, including private) of the outer class.
3.Where can a local inner class be declared?
-
A. Only at the top level of a class.
-
B. Inside a method, constructor, or block.
-
C. Only inside an interface.
-
D. Inside another inner class only.
Inside a method, constructor, or block.
Inside a method, constructor, or block.
4.Which of the following is true about anonymous inner classes?
-
A. They can be instantiated multiple times.
-
B. They must extend a class or implement an interface.
-
C. They always have a name.
-
D. They cannot access local variables of the enclosing scope.
They must extend a class or implement an interface.
They must extend a class or implement an interface.
5.What is the main advantage of using inner classes?
-
A. To improve performance of the application.
-
B. To group classes that logically belong together and control access.
-
C. To reduce the memory footprint.
-
D. To simplify multithreading.
To group classes that logically belong together and control access.
To group classes that logically belong together and control access.