Java Quiz: Type Casting

This Java type casting quiz covers widening and narrowing conversions between primitives and casts between objects. You will predict what casts truncate or overflow, spot code that needs an explicit cast and see when a cast fails at runtime.

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

मोड चुनें

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

सैंपल सवाल

सवाल 1 / 10

What does this print?

public class Main {
    public static void main(String[] args) {
        double d = 9.99;
        int i = (int) d;
        System.out.println(i);
    }
}
जवाब दिखाएं

A. 9 Casting a double to int truncates toward zero, it never rounds. Use Math.round(d) if you want 10.

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

  • Widening conversions vs narrowing casts
  • Truncation and overflow when narrowing
  • Overflow before widening in int arithmetic
  • Rounding with Math.round
  • Casting objects and ClassCastException

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

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

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

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

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