Question

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

Option 4 : 3

Advertisement

Detailed Solution

सही उत्तर 3 है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following Java program? int m() { try { return 1; } catch (Exception e) { return 2; } finally { return 3; } } System.out.print(m()); / निम्नलिखित Java प्रोग्राम का आउटपुट क्या है?

1.
1
2.
2
3.
Compile-time error
4.
3

Correct Answer: 3

The finally block always executes, and a return inside finally overrides the pending return 1 from the try block, so the method returns 3. / finally ब्लॉक हमेशा निष्पादित होता है, और finally के अंदर का return, try ब्लॉक के लंबित return 1 को ओवरराइड कर देता है, इसलिए मेथड 3 लौटाता है।

Downloaded from PrepSnap (prepsnap.in)