JVM基础性问题,说出以下代码的输出结果,并作出详细的解释。

第一题:


public class StringConstant {



public static void main(String[] args) {
String a = "abc";
judge(a,"abc");
String b = new String("abc");
judge(a,b);

String c = "a" +"bc";
judge(a,c);
String d = new String("a"+"bc");

judge(a,d);

String d = "a";


String f = "bc";


String g = d +f ;

judge(a,g);


String h = "c";

String i = "ab"+h;

judge(a,i);


final String k ="c";

String l = "ab" + k;

judge(a,l); 


final String m = get();

String n = "a"+m+"c";

judge(a,n);


judge(n.intern(),a)

}


static String get(){

return "b";

}


static void judge(String a ,String b){

System.out.println((a==b));

}

}


第二题:

public class StringConstant {


static {

System.out.println("StringConstant static region");

}



StringConstant(){

System.out.println("StringConstant construct");

}


public static void main(String[] args) {

new DesignMode();

}



}



class DesignMode extends StringConstant{

static {

System.out.println("DesignMode static region");

}



DesignMode(){

System.out.println("DesignMode construct");

}


}


第三题:


public class ReturnFinally
{

  public static void main(String[] args)

{

//用例 1:

    try

    {

    throwException();

    } catch (Exception e) {

   System.out.println(" catch 1 ");

    return;

    } finally {

    System.out.println(" finally 1");

    }



// 用例 2:

int i = 0;
i = subFunc();
System.out.println(i);

       }


  private static void throwException() throws Exception {

    try {

    double d = 1 / 0;

    } catch (Exception e) {

    System.out.println(" catch 2 :" + e.getMessage());

   return;

    } finally {

    System.out.println("finally 2");

    throw new Exception();

    }

  }


private static int subFunc() {

try{

System.out.println(" try subFunc ... ...");

throw new Exception();

}catch(Exception e){

System.out.println(" catch subFunc ... ...");

//注释  和 不注释 下面语句 区别

System.exit(0);

return 0;

}finally{

System.out.println(" finally subFunc ... ...");

return 1;

}


}

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值