河南成教 / 河南理工大学
14[分析题]
public class Test
{
public static void main(String[] args)
{
int val;
StringBuffer sb1,sb2;
val=10;
sb1=new StringBuffer("apples");
sb2=new StringBuffer("pears");
System.out.println("val=" val);
System.out.println("sb1=" sb1);
System.out.println("sb2=" sb2);
System.out.println("");
System.out.println("calling modify");
modify(val,sb1,sb2);
System.out.println("return from modify");
System.out.println("");
System.out.println("val=" val);
System.out.println("sb1=" sb1);
System.out.println("sb2=" sb2);
}
public static void modify(int a,StringBuffer r1,StringBuffer r2)
{
System.out.println("in modify....");
a=0;
r1=null;
r2.append("taste good");
System.out.println("val=" a);
System.out.println("sb1=" r1);
System.out.println("sb2=" r2);
}
}
上述代码执行后的结果是?
14[分析题]
public class Test
{
public static void main(String[] args)
{
int val;
StringBuffer sb1,sb2;
val=10;
sb1=new StringBuffer("apples");
sb2=new StringBuffer("pears");
System.out.println("val=" val);
System.out.println("sb1=" sb1);
System.out.println("sb2=" sb2);
System.out.println("");
System.out.println("calling modify");
modify(val,sb1,sb2);
System.out.println("return from modify");
System.out.println("");
System.out.println("val=" val);
System.out.println("sb1=" sb1);
System.out.println("sb2=" sb2);
}
public static void modify(int a,StringBuffer r1,StringBuffer r2)
{
System.out.println("in modify....");
a=0;
r1=null;
r2.append("taste good");
System.out.println("val=" a);
System.out.println("sb1=" r1);
System.out.println("sb2=" r2);
}
}
上述代码执行后的结果是?
参考答案: