Loading
Java - Type casting Overview

Q1.

Which of the following is an example of widening typecasting?

A. double → int

B. int → double

C. float → byte

D. long → short

Q2.

What is required for narrowing typecasting in Java?

A. Automatic conversion

B. Explicit casting by the programmer

C. No conversion needed

D. JVM handles it automatically

Q3.

 Which of the following is true about upcasting in Java?

A. It requires explicit casting

B. It is converting superclass reference to subclass reference

C. It is converting subclass reference to superclass reference

D. It is not allowed in Java

Q4.

What will be the output of the following code?


double d = 9.7;

int i = (int) d;

System.out.println(i);

A. 9.7
B. 10
C. 9
D. Compilation error

Q5.

Which of the following may throw a ClassCastException at runtime?

A. Widening primitive casting

B. Narrowing primitive casting

C. Upcasting

D. Downcasting