Question

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

Option 1 : C / C

Advertisement

Detailed Solution

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

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following Java program involving dynamic method dispatch through a superclass reference? / सुपरक्लास संदर्भ के माध्यम से गतिशील मेथड डिस्पैच वाले निम्नलिखित Java प्रोग्राम का आउटपुट क्या होगा? class Shape { void draw() { System.out.print("S"); } } class Circle extends Shape { void draw() { System.out.print("C"); } } public class T { static void render(Shape s) { s.draw(); } public static void main(String[] args) { render(new Circle()); } }

1.
C / C
2.
S / S
3.
CS / CS
4.
Runtime error / रनटाइम त्रुटि

Correct Answer: C / C

The overridden draw() is selected at run time from the actual object type, Circle, so "C" is printed. / ओवरराइड किया गया draw() रनटाइम पर वास्तविक ऑब्जेक्ट प्रकार Circle से चुना जाता है, इसलिए "C" छपता है।

Downloaded from PrepSnap (prepsnap.in)