问题:class Person{ protected String name,sex,city; protected int age; public Person(String n,String s,String c,int a)//超类的构造方法 { this.name=n; this.sex=s; this.city=c; this.age=a; } public void ShowInfo() { System.out.print(姓名\t+name+\t); System.out.print(年龄\t+age+\t); System.out.print(性别\t+sex+\t); System.out.print(城市\t+city+\t); }}class Student extends Person{ int num,eglish,maths,computer; String dept;//添加子类成员 Student(String n,String s,String c,String d,int nu,int a,int e,int m,int co) { super(n,s,c,a); num=nu; dept=d; eglish=e; maths=m; computer=co; } int ave() { int av=(eglish+maths+computer)/3; return av; }public void ShowInfo() { super.ShowInfo(); System.out.print(学号\t+num+\t); System.out.print(系别\t+dept+\t); System.out.print(英语\t+eglish+数学\t+maths+计算机\t+computer); } }class Teacher extends Person{ int money; String Dop; Teacher(String n,String s,String c,String D,int m,int a) { super(n,s,c,a); money=m; Dop=D; } public void ShowInfo() { super.ShowInfo(); System.out.print(工资\t+money+\t); System.out.print(实验室\t+Dop+\t); }}public class QQ{ public static void main(String arg[]) { Person p; p=new Person(王二,男,北京,18); p.ShowInfo(); System.out.println(); Student s1 =new Student(张三,男,上海,计算机,32,12,222,333,444); s1.ShowInfo(); System.out.print(总分:+s1.ave); System.out.println(); p=new Teacher(李四,女,武汉,计算机实验室,3200,45); p.ShowInfo(); System.out.println(); }}这个我写的程序..运行的时出现这样提示QQ.java:67: 找不到符号符号: 变量 ave位置: 类 Student System.out.print(总分:+s1.ave);望高手解决!!
位置: 类 Student System.out.print("总分:"+s1.ave);
s1.ave改成s1.ave()
输出结果: 姓名 王二 年龄 18 性别 男 城市 北京 姓名 张三 年龄 12 性别 男 城市 上海 学号 32 系别 计算机 英语 222数学 333计算机 444总分:333 姓名 李四 年龄 45 性别 女 城市 武汉 工资 3200 实验室 计算机实验室 如果你对class Person{ protected String name,sex,city; protected int age; public Person(String n,String s,String c,int a)//超类的构造方法 { this.name=n; this.sex=s; this.city=c; this.age=a; } public void ShowInfo() { System.out.print(姓名\t+name+\t); System.out.print(年龄\t+age+\t); System.out.print(性别\t+sex+\t); System.out.print(城市\t+city+\t); }}class Student extends Person{ int num,eglish,maths,computer; String dept;//添加子类成员 Student(String n,String s,String c,String d,int nu,int a,int e,int m,int co) { super(n,s,c,a); num=nu; dept=d; eglish=e; maths=m; computer=co; } int ave() { int av=(eglish+maths+computer)/3; return av; }public void ShowInfo() { super.ShowInfo(); System.out.print(学号\t+num+\t); System.out.print(系别\t+dept+\t); System.out.print(英语\t+eglish+数学\t+maths+计算机\t+computer); } }class Teacher extends Person{ int money; String Dop; Teacher(String n,String s,String c,String D,int m,int a) { super(n,s,c,a); money=m; Dop=D; } public void ShowInfo() { super.ShowInfo(); System.out.print(工资\t+money+\t); System.out.print(实验室\t+Dop+\t); }}public class QQ{ public static void main(String arg[]) { Person p; p=new Person(王二,男,北京,18); p.ShowInfo(); System.out.println(); Student s1 =new Student(张三,男,上海,计算机,32,12,222,333,444); s1.ShowInfo(); System.out.print(总分:+s1.ave); System.out.println(); p=new Teacher(李四,女,武汉,计算机实验室,3200,45); p.ShowInfo(); System.out.println(); }}这个我写的程序..运行的时出现这样提示QQ.java:67: 找不到符号符号: 变量 ave位置: 类 Student System.out.print(总分:+s1.ave);望高手解决!!这个问题有好的意见或
建议,请留言
|