首页 > 学院 > 开发设计 > 正文

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

2019-11-06 08:11:39
字体:
来源:转载
供稿:网友

第一题:

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)

{

    try

    {

    throwException();

    } catch (Exception e) {

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

    return;

    } finally {

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

    }

       }

  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");

    new Throwable();

    }

  }

}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表