Question
1.
2.
3.
4.
Answer (Detailed Solution Below)
Option 3 : A
Advertisement
Detailed Solution
सही उत्तर A है।
Key Points
Helpful?
Question:
What is the output of the following Java program involving static method hiding? / स्टैटिक मेथड हाइडिंग वाले निम्नलिखित जावा प्रोग्राम का आउटपुट क्या है? class A { static void m() { System.out.print("A"); } } class B extends A { static void m() { System.out.print("B"); } } class Test { public static void main(String[] args) { A a = new B(); a.m(); } }
1.
B
2.
AB
3.
A
4.
Compilation fails / संकलन विफल होगा
Correct Answer: A
Static methods are hidden, not overridden — the call a.m() binds at compile time to the reference type A, printing "A". / स्टैटिक मेथड ओवरराइड नहीं, हाइड होते हैं — a.m() कॉल कंपाइल-टाइम पर रेफरेंस प्रकार A से बाइंड होता है, "A" प्रिंट होता है।
Downloaded from PrepSnap (prepsnap.in)