package eclipse;
public class q {
int age;
void getAge(int age) {
this.age=age;
}
int showAge() {
System.out.println("年龄是"+getAge());
}
//The method getAge(int) in the type q is not applicable for the arguments ()
//上面这一行是错误提示,是什么意思啊?
public static void main(String agrs[]) {
q w=new q();
w.showAge();
w.getAge(9);
q e=new q();
e.getAge(10);
e.showAge();
}
}
参数不能用,你两个方法代码写反了
package T1;
public class Q {
int age;
int getAge() {
return age;
}
void setAge(int age) {
this.age = age;
}
void showAge() {
System.out.println("年龄是:" + getAge());
}
public static void main(String agrs[]) {
Q q = new Q();
q.setAge(9);
q.showAge();
Q e = new Q();
e.setAge(10);
e.showAge();
}
}
package T1;
public class Q {
int age;
int getAge() {
return age;
}
void setAge(int age) {
this.age = age;
}
void showAge() {
System.out.println("年龄是:" + getAge());
}
public static void main(String agrs[]) {
Q q = new Q();
q.setAge(9);
q.showAge();
Q e = new Q();
e.setAge(10);
e.showAge();
}
}
方法没有声明是public
你这个基础知识不到位,你写一个返回类型是int的方法,你就写了局输出语句,没有返回语句,肯定