Question
1.
2.
3.
4.
Answer (Detailed Solution Below)
Option 1 : A7 / A7
Advertisement
Detailed Solution
सही उत्तर A7 / A7 है।
Key Points
Helpful?
Question:
What is the output of the following Java program involving constructor chaining with this()? / this() के साथ कंस्ट्रक्टर चेनिंग वाले निम्नलिखित Java प्रोग्राम का आउटपुट क्या होगा? class A { A() { System.out.print("A"); } A(int n) { this(); System.out.print(n); } } public class T { public static void main(String[] args) { new A(7); } }
1.
A7 / A7
2.
7A / 7A
3.
A / A
4.
Compilation error / संकलन त्रुटि
Correct Answer: A7 / A7
The parameterized constructor first delegates to the no-argument constructor via this(), printing "A", and then prints 7. / पैरामीटरयुक्त कंस्ट्रक्टर पहले this() से बिना-तर्क वाले कंस्ट्रक्टर को बुलाता है, "A" छापता है, और फिर 7 छापता है।
Downloaded from PrepSnap (prepsnap.in)