Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 3 : ABb / एबीबी

Advertisement

Detailed Solution

सही उत्तर ABb / एबीबी है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

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(); } }

1.
ABa / एबीए
2.
Aa / एए
3.
ABb / एबीबी
4.
Compilation fails / संकलन विफल होगा

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"।

Downloaded from PrepSnap (prepsnap.in)