看到外面有个帖子 ,发现里面的题目都是java 解惑里的哈,最近再读,所以把精彩的给大家分享一下
下面的测试你弟 instanceof 和转型的理解
public class Type1{
  public static void main(String [] args){
String s=null;
System.out.println(s. instanceof String);
}
}
public class Type2{
    public static void main(String [] args){
   System.out.println(new Type2() instanceof String);}public class Type3{
    public static void main(String [] args){    Type3 t3=(Type3) new Obejct();
}}}
不要debug 给出自己的结果对的拿分哈 ,debug的木有小JJ  

解决方案 »

  1.   

    1.instanceof    null对于每一个引用类型来说都是它的子类型,但是 instanceof 规定当左操作符为 null的时候 返回false,这样是为了在转型测试的时候不会抛出空指针异常另外 instanceof要求 :如果两个操作数的单类型都是类,其中一个必须是另一个的子类型,如 new Type()instanceof  String  ,会引起编译时错误强制类型转换与instanceof要求相同,但是(Type3)new Object在编译时期不会出现问题 ,在运行时 抛出 ClassCastException  
      

  2.   

    1.true
    2.false
    3.抛出异常