为什么我通过引用示例obj1.add200really
在传递中出现错误带有下划线
public class Test {
private int number;
Test(){
number = 1;
}
public static void main(String[] args) {
Test obj1 = new Test();
System.out.println("the number is " + obj1.number);
System.out.println("the number 1 plus 200 is " + obj1.add200(obj1.number));
System.out.println("while the number is still " + obj1.number);
System.out.println("\n");
System.out.println("the number is " + obj1.number);
System.out.println("the number 1 plus 200 is " + obj1.add200really(obj1.number));
System.out.println("while the number is still " + obj1.number);
}
int add200(int somenumber){
somenumber = somenumber + 200;
return somenumber;
}
int add200really(Test myobj){
myobj.number = 999;
return myobj.number;
}
}
答案 0 :(得分:1)
使用obj1.add200really(obj1);
答案 1 :(得分:0)
因为您没有方法add200really(int)
您的方法add200really()
需要一个对象。您正尝试使用int