Question

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

Option 1 : 1423562356

Advertisement

Detailed Solution

सही उत्तर 1423562356 है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following Java program involving static and instance initialisers? / स्टैटिक और इंस्टेंस इनिशियलाइज़र वाले निम्नलिखित जावा प्रोग्राम का आउटपुट क्या है? class P { static { System.out.print("1"); } { System.out.print("2"); } P() { System.out.print("3"); } } class Q extends P { static { System.out.print("4"); } { System.out.print("5"); } Q() { System.out.print("6"); } } class Test { public static void main(String[] args) { new Q(); new Q(); } }

1.
1423562356
2.
142356142356
3.
123456123456
4.
1234562356

Correct Answer: 1423562356

Static blocks run once at class loading (parent first: "1", then "4"); each new Q() runs instance initialisers and constructors parent-first: "2","3","5","6" — twice. Output "1423562356". / स्टैटिक ब्लॉक क्लास लोडिंग पर एक बार चलते हैं (पहले पैरेंट: "1", फिर "4"); हर new Q() पर इंस्टेंस इनिशियलाइज़र और कंस्ट्रक्टर पैरेंट-पहले क्रम में चलते हैं: "2","3","5","6" — दो बार। आउटपुट "1423562356"।

Downloaded from PrepSnap (prepsnap.in)