AllInfoHub Logo

AllInfoHub – MCQ Practice

Classes and Objects – Multiple Choice Questions (MCQs)

  1. 37. What is the output of the following code? `class Outer { int x = 10; class Inner { int y = 5; void display() { System.out.println(x + y); } } public static void main(String[] args) { Outer outer = new Outer(); Outer.Inner inner = outer.new Inner(); inner.display(); } }`

    • A. 10
    • B. 5
    • C. 15
    • D. Error
  2. 38. What is an anonymous inner class in Java?

    • A. An inner class without a name
    • B. An inner class that is static
    • C. An inner class defined outside another class
    • D. An inner class that cannot access outer class members
  3. 39. What is the output of the following code? `interface MyInterface { void show(); } public class AnonymousInner { public static void main(String[] args) { MyInterface obj = new MyInterface() { public void show() { System.out.println(\Anonymous\"); } }; obj.show(); } }`"""

    • A. MyInterface
    • B. AnonymousInner
    • C. Anonymous
    • D. Error