当前位置: 技术问答>java相关
这个程序为什么会抛出例外!
来源: 互联网 发布时间:2015-05-16
本文导语: import java.io.*; import java.lang.*; public class test { void operate(StringBuffer x, StringBuffer y) { y.append(x); y = x; System.out.println(y); return;} public static void main (String[] args) { test t =...
import java.io.*;
import java.lang.*;
public class test {
void operate(StringBuffer x, StringBuffer y) {
y.append(x);
y = x;
System.out.println(y);
return;}
public static void main (String[] args) {
test t = new test();
StringBuffer a = new StringBuffer("A");
StringBuffer b = new StringBuffer("B");
t.operate(a,b);
System.out.println(a + "," +b);
}
}
import java.lang.*;
public class test {
void operate(StringBuffer x, StringBuffer y) {
y.append(x);
y = x;
System.out.println(y);
return;}
public static void main (String[] args) {
test t = new test();
StringBuffer a = new StringBuffer("A");
StringBuffer b = new StringBuffer("B");
t.operate(a,b);
System.out.println(a + "," +b);
}
}
|
没有exception,运行结果为:
A
A,BA
A
A,BA
|
我运行了一下,也没有异常的。
结果也是:
A
A,BA
结果也是:
A
A,BA
|
加上PUBLIC
public void operate(StringBuffer)
public void operate(StringBuffer)
|
一点问题都没有,我用的也是1.4
---------- Run Java File ----------
A
A,BA
Normal Termination
Output completed (2 sec consumed).
---------- Run Java File ----------
A
A,BA
Normal Termination
Output completed (2 sec consumed).