Inner Classes Questions and Answers
In Java Programming, Inner Classes allow you to define a class within another class, enhancing encapsulation and code readability. This topic frequently appears in TCS, Accenture, and Infosys Java interview questions. In this section on Inner Classes questions with answers, you’ll explore member inner classes, static nested classes, anonymous inner classes, and local inner classes. Practicing these Java programming MCQs helps you understand how nested classes interact with outer classes and how they improve object-oriented design. Detailed explanations provided with each question will strengthen your grasp on Java scope, access modifiers, and real-world use cases — making it perfect for technical interview preparation.
Inner Classes
Showing 10 of
27 questions
21. Which of the following is true about anonymous inner classes?
- They can have constructors
- They can extend a class and implement multiple interfaces
- They can implement multiple interfaces
- They can extend one class or implement one interface
22. What is the bytecode file name for a member inner class?
- InnerClass.class
- OuterClass_InnerClass.class
- OuterClass$InnerClass.class
- OuterClass.InnerClass.class
23. Can we have static methods in a member inner class?
- Yes, they can have static methods
- No, they cannot have static methods
- Only if the outer class is also static
- Only static final variables are allowed
24. Which inner class is commonly used for event handling in GUI?
- Static nested class
- Member inner class
- Local inner class
- Anonymous inner class
25. Can an outer class access private members of inner class?
- No, never
- Yes, always
- Only if the inner class is static
- Only if the members are protected
26. What happens if you declare an inner class as final?
- It cannot be instantiated
- It cannot be extended
- It becomes immutable
- It cannot access outer class members
27. Which of the following is NOT a type of inner class in Java?
- Member inner class
- Local inner class
- Abstract inner class
- Anonymous inner class