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.

Mittel 10 Fragen ~6 Minuten Bestanden ab 80% Java 17

Modus wählen

Du spielst als Gast: Melde dich an, damit XP und Serie gespeichert werden.

Beispielfrage

Frage 1 von 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);
    }
}
Lösung zeigen

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

Darum geht es in diesem Quiz

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

Häufige Fragen

Brauche ich ein Konto?

Nein. Jeder kann spielen. Mit Anmeldung werden XP, Serie, Abzeichen und Verlauf gespeichert.

Kann ich es wiederholen?

Ja. Dein Bestwert bleibt erhalten, und Fragen und Antworten werden jedes Mal neu gemischt.