Question

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

Option 1 : A / A

Advertisement

Detailed Solution

सही उत्तर A / A है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following Java program involving static methods bound to the reference type? / संदर्भ प्रकार से बँधने वाले स्टैटिक मेथड वाले निम्नलिखित Java प्रोग्राम का आउटपुट क्या होगा? class A { static void show() { System.out.print("A"); } } class B extends A { static void show() { System.out.print("B"); } } public class T { public static void main(String[] args) { A ref = new B(); ref.show(); } }

1.
A / A
2.
B / B
3.
AB / AB
4.
Compilation error / संकलन त्रुटि

Correct Answer: A / A

Static methods are hidden, not overridden; the call is bound at compile time to the reference type A, so "A" is printed. / स्टैटिक मेथड ओवरराइड नहीं, हाइड होते हैं; कॉल संकलन समय पर संदर्भ प्रकार A से बँधती है, इसलिए "A" छपता है।

Downloaded from PrepSnap (prepsnap.in)