编写出一个通用的人员类(Person),该类具有姓名(Name)、年龄(Age)、性别(Sex) 2等域。然后对Person类的继承得到一个学生类(Student),该类能够存放学生的5门课的成绩,并能求出平均成绩。最后在Main 函数中对student类的功能进行验证。
class Person{ String name; String age; String sex; } class Student extends Person{ double zh;//中文 double en;//英文 double math;//数学 double gov;//政治 double history;//历史
set ...
get ...
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-type">double</span> <span class="hljs-title">avg</span><span class="hljs-params">(Student stu)</span></span>{
<span class="hljs-keyword">return</span> (stu.zh + stu.en + stu.math + stu.gov + stu.history)/<span class="hljs-number">5</span>;
}
public static void main(String[] args){ Student stu = new Person(); stu.setZh....... System.Out.print(avg(stu)) }
}