有几个关于类型转换的比试题问问大家 最好能说说原理
1 Consider the following piece of code, 看下面的代码:
1 String s = "abcd";
2 Integer x = new Integer(3);
3 String s2 = s + 4;
4 s2 = null;
5 s = null;Following the execution of which line above, is the object reference by s2 available for garbage collection?(上面各行的执行,s2对象引用可以被垃圾收集么)A Line5
B It is not possible to say when an object is available for Garbage collection(说一个对象可以被垃圾收集是不可能的)
C Line4
D The object is available untile the executing thread is ended
(知道执行线程结束对象才可用)2 Which of the following will compile correctly?
A Short myshort = 99S;
B int t = "abc".length();
C float z = 1.0;
D char c =17c;3 下面代码输出结果是:
int i = 012;
int j = 034;
int k = (int)056L;
int l = 078;
System.out.println(i);
System.out.println(j);
System.out.println(k);
A 输出 12,34,56
B 输出 10,28,46
C int k = (int)056L;行编译错误
D int l = 078;行编译错误

解决方案 »

  1.   

    int l = 078 为什么会编译错误呢?
      

  2.   

    谢谢楼上
    Short myshort = 99S;  这种写法不对么??
    float z = 1.0; 为什么也通不过?
      

  3.   

    Short myshort = 99S;这句要执行自动装箱,调用shortValue()方法,显然99S无法得到值。
    float z = 1.0;改为float z=1.0f;就行了。系统默认浮点数是double型。
      

  4.   

    楼上你好 : 
    Short myshort = 99S;  这种写法不对 那该怎么写好呢?
      

  5.   

    Short myshort = 99;short myshort=99;Short myshort=new Short((short)99);
      

  6.   

    对不起 我还有疑问 s2 = null s = null
    两个都置空了
    那么垃圾处理器 就可以把它原来分配的内存干掉了吧