class Letter{
char c;
}
public class PassObject{
static void f(Letter y){
y.c= 'z ';}
public static void main(String args[]){
x.c= 'a ';
System.out.println(x.c);
f(x);
System.out.println(x.c);
}
}
------解决方案--------------------
class Letter{
public Letter(){}
char c;
}
public static void main(String args[]){
Letter x=new Letter();
x.c= 'a ';
System.out.println(x.c);
f(x);
System.out.println(x.c);
}
------解决方案--------------------
class Letter{
char c;
}
public class PassObject{
static void f(Letter y){
y.c= 'z ';
}
public static void main(String args[]){
Letter x=new Letter(); //实例化
x.c= 'a ';
System.out.println(x.c);
f(x);
System.out.println(x.c);
}
}
------解决方案--------------------
楼主的C是在方法里定义的,不是类的变量,所以无法用类的实例调用
应该是这样的
------解决方案--------------------
lz的程序错误真不少,lz加油!