Which exception will the following throw?
Object obj = new Integer(3);
String str = (String) obj;
System.out.println(str);
B.
The second line tries to cast an Integer to a String and throws ClassCastException.
public class Main { public static void main(String[] args) { Object obj = new Integer(3); String str = (String) obj; System.out.println(str); } }
The code above generates the following result.