Question

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

Option 3 : Each resource is closed automatically at the end of the try block / try ब्लॉक के अंत में प्रत्येक संसाधन स्वतः बंद हो जाता है

Advertisement

Detailed Solution

सही उत्तर Each resource is closed automatically at the end of the try block / try ब्लॉक के अंत में प्रत्येक संसाधन स्वतः बंद हो जाता है है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

Which statement about Java's try-with-resources is TRUE? / Java के try-with-resources के बारे में कौन-सा कथन सत्य है?

1.
You must still call close() explicitly in the finally block / finally ब्लॉक में close() स्पष्ट रूप से बुलाना आवश्यक है
2.
Resources are closed only if an exception occurs / संसाधन केवल अपवाद होने पर बंद होते हैं
3.
Each resource is closed automatically at the end of the try block / try ब्लॉक के अंत में प्रत्येक संसाधन स्वतः बंद हो जाता है
4.
It works with any object, even those not implementing AutoCloseable / यह किसी भी ऑब्जेक्ट के साथ काम करता है, चाहे वह AutoCloseable implement न करता हो

Correct Answer: Each resource is closed automatically at the end of the try block / try ब्लॉक के अंत में प्रत्येक संसाधन स्वतः बंद हो जाता है

Resources declared in the try-with-resources header (which must implement AutoCloseable) are closed automatically, in reverse order, when the block exits — normally or via exception. The trap option (d) ignores the AutoCloseable requirement. / try-with-resources header में घोषित संसाधन (जिन्हें AutoCloseable implement करना चाहिए) ब्लॉक से बाहर निकलते समय — सामान्यतः या अपवाद द्वारा — स्वतः, उल्टे क्रम में बंद होते हैं। जाल विकल्प (d) AutoCloseable की आवश्यकता को नज़रअंदाज़ करता है।

Downloaded from PrepSnap (prepsnap.in)