每日代码系列(17)

1 interface Achievement {
 2   public abstract float average();
 3 }
 4 class Person {
 5   String name;
 6   int age;
 7   public Person(String newName,int newAge) {
 8     name=newName;
 9     age=newAge;
10   }
11   public void introduce() {
12     System.out.println("你好,我是"+name+",今年"+age+"岁");
13   }
14 }
15 class Student extends Person implements Achievement {
16   int chinese,math,english;
17   public Student(String newName,int newAge) {
18     super(newName,newAge);
19   }
20   public void setScore(int c,int m,int e) {
21     chinese=c;
22     math=m;
23     english=e;
24   }
25   public float average() {
26     return (chinese+math+english)/3;
27   }
28 }
29 class C3_2 {
30   public static void main(String[] args) {
31     Student s1=new Student("张三",16);
32     s1.introduce();
33     s1.setScore(80,90,80);
34     System.out.println("平均分: "+s1.average());
35   }
36 }

补上周六欠的。

Original: https://www.cnblogs.com/ljydbk/p/14128050.html
Author: 李家宇
Title: 每日代码系列(17)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/584531/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球