Question
1.
2.
3.
4.
Answer (Detailed Solution Below)
Option 4 : 2
Advertisement
Detailed Solution
सही उत्तर 2 है।
Key Points
Helpful?
Question:
What is printed by the following Java program? / निम्नलिखित जावा प्रोग्राम क्या प्रिंट करेगा? class Test { static int f() { try { return 1; } finally { return 2; } } public static void main(String[] args) { System.out.print(f()); } }
1.
1
2.
3
3.
Compilation fails / संकलन विफल होगा
4.
2
Correct Answer: 2
A return inside finally overrides the return value prepared by the try block, so f() returns 2. / finally के अंदर का return, try ब्लॉक द्वारा तैयार रिटर्न मान को ओवरराइड कर देता है, इसलिए f() 2 लौटाता है।
Downloaded from PrepSnap (prepsnap.in)