Question
Option 1 : A2 A1 B
Detailed Solution
सही उत्तर A2 A1 B है।
Question:
What is the output of the following Java program involving constructor chaining with this() and super()? / this() और super() के साथ कंस्ट्रक्टर चेनिंग वाले निम्नलिखित जावा प्रोग्राम का आउटपुट क्या है? class A { A() { this(5); System.out.print("A1 "); } A(int n) { System.out.print("A2 "); } } class B extends A { B() { super(); System.out.print("B "); } } class Test { public static void main(String[] args) { new B(); } }
Correct Answer: A2 A1 B
B() calls super() → A() calls this(5) → A(int) prints "A2 ", control returns to A() which prints "A1 ", then B() prints "B ". / B() super() बुलाता है → A() this(5) बुलाता है → A(int) "A2 " प्रिंट करता है, नियंत्रण A() में लौटकर "A1 " प्रिंट करता है, फिर B() "B " प्रिंट करता है।