PersonDemo.java:35: 找不到符号
发布网友
发布时间:2023-09-08 20:29
我来回答
共2个回答
热心网友
时间:2024-12-04 18:14
问题主要有2个:
1、ave是方法,不是变量,必须用ave();
2、Person class不包含setDate方法,你定义为Person类,调用时,就只能使用Person及其父类有定义的方法和属性
如:
class Person{
void setDate(double e,double m,double c){
//放一个空方法就好
}
}
热心网友
时间:2024-12-04 18:14
class Person {
String name, sex, city;
int age;
Person(String n, String s, String c, int a) {
name = n;
sex = s;
city = c;
age = a;
}
void showInfor() {
System.out.println(name + "\t" + age + "\t" + sex + "\t" + city);
}
}
class Student extends Person {
int num;
double english, maths, computer;
String dept;
Student(String n, String s, String c, String dept, int num, int a) {
super(n, s, c, a);
this.num = num;
this.dept = dept;
}
void setDate(double e, double m, double c) {
english = e;
maths = m;
computer = c;
}
double ave() {
double ave = (english + maths + computer) / 3.0;
return ave;
}
void showInfor() {
super.showInfor();
System.out.print("the Student\t" + name + "\t");
System.out.print(num + "\t" + dept);
System.out.print(english + "\t" + maths + "\t" + computer + "\t" + ave());
}
}
class Teacher extends Person {
int wage;
String lab;
Teacher(String n, String s, String c, String lab, int wage, int a) {
super(n, s, c, a);
this.wage = wage;
this.lab = lab;
}
void showInfor() {
super.showInfor();
System.out.print("the Teacher\t" + name + "\t");
System.out.print(wage + "\t" + lab);
}
}
class PersonDemo {
public static void main(String args[]) {
Person a;
a = new Student("小飞", "男", "成都", "数学系", 2006061038, 20);
((Student) a).setDate(96.0, 98.0, 88.0);
a.showInfor();
Teacher b = new Teacher("刘易", "男", "成都", "数学实验室", 3600, 43);
b.showInfor();
}
}
错误如楼上所说,我把你错的都改了。 最后鄙视一楼的。完毕