下面的代码会抛出哪种异常?( )
public class Test {
public static void main(String[] args) {
Object obj = new Integer(3);
String str = (String) obj;
System.out.println(str);
}
}ArrayIndexOutOfBoundsException
ClassCastException
IllegalArgumentException
NumberFormatException
以上都不是
第二行试图将整数转换为字符串。由于String没有扩展Integer,因此不允许这样做,并抛出了ClassCastException。