第一题:
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();
}
}
}
新闻热点
疑难解答