ควิซ Java: 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, เหรียญตรา และประวัติ

ทำซ้ำได้ไหม?

ได้ ระบบเก็บคะแนนที่ดีที่สุดไว้ และสลับคำถามกับตัวเลือกใหม่ทุกครั้ง