Java Quiz: try, catch & finally

This Java quiz walks through try, catch and finally, including the cases that surprise people, like a return inside finally. You will also trace try-with-resources and see when resources get closed.

मीडियम 10 सवाल ~6 मिनट पास होने के लिए 80% Java 17

मोड चुनें

आप गेस्ट के तौर पर खेल रहे हैं: XP और streak सेव रखने के लिए साइन इन करें।

सैंपल सवाल

सवाल 1 / 10

What does this print?

public class Main {
    static String test() {
        try {
            return "try";
        } finally {
            System.out.print("finally ");
        }
    }

    public static void main(String[] args) {
        System.out.println(test());
    }
}
जवाब दिखाएं

B. finally try The return value is computed first, then finally runs before the method actually returns. So finally is printed inside test(), and try is printed afterwards by main.

इस क्विज़ में क्या है

  • The order of try, catch, finally and the code after them
  • finally after return, and return inside finally
  • Returning a primitive vs an object from try
  • Catch block order and exceptions thrown from catch
  • Try-with-resources, AutoCloseable and close order

अक्सर पूछे जाने वाले सवाल

क्या अकाउंट ज़रूरी है?

नहीं। कोई भी खेल सकता है। XP, streak, badge और हिस्ट्री सेव रखने के लिए साइन इन करें।

क्या मैं इसे दोबारा दे सकता हूं?

हां। आपका बेस्ट स्कोर सेव रहता है, और हर बार सवाल और जवाब शफ़ल होते हैं।