Question
Option 3 : ABb / एबीबी
Detailed Solution
सही उत्तर ABb / एबीबी है।
Question:
Consider the following Java program. What will be printed when it is executed? / निम्नलिखित जावा प्रोग्राम पर विचार करें। इसे चलाने पर क्या प्रिंट होगा? class A { A() { System.out.print("A"); } void show() { System.out.print("a"); } } class B extends A { B() { System.out.print("B"); } void show() { System.out.print("b"); } } class Test { public static void main(String[] args) { A x = new B(); x.show(); } }
Correct Answer: ABb / एबीबी
Creating B runs A's constructor ("A") then B's ("B"); x.show() uses dynamic dispatch, so B's show() prints "b" — output "ABb". / B बनाने पर पहले A का कंस्ट्रक्टर ("A") फिर B का ("B") चलता है; x.show() डायनामिक डिस्पैच से B का show() चलाता है जो "b" प्रिंट करता है — आउटपुट "ABb"।