11.13 第十二次
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了11.13 第十二次相关的知识,希望对你有一定的参考价值。
package GJS; public abstract class Person { private String name; private int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public Person(String name, int age) { this.name = name; this.age = age; } public Person() { super(); } @Override public String toString() { return "Person [name=" + name + ", age=" + age + "]"; } public abstract String speak(); }
package GJS; public class Student extends Person{ private float score; public Student(String name, int age, float score) { super(name, age); this.setScore(score); } @Override public String speak() { return "学生说:我叫"+super.getName()+" "+"今年"+super.getAge()+"岁 "+this.score+"分"; } public float getScore() { return score; } public void setScore(float score) { this.score = score; } }
package GJS; public class Worker extends Person { private float salary; public Worker(String name, int age, float salary) { super(name, age); this.setSalary(salary); } @Override public String speak() { return "工人说:我叫"+super.getName()+" "+"今年"+super.getAge()+"岁 "+this.salary+"元"; } public float getSalary() { return salary; } public void setSalary(float salary) { this.salary = salary; } }
package GJS; public class DemoStudentWorker { public static void main(String[] args) { Person student=new Student("QQQ",21, 86f); Person worker=new Worker("WWW",32, 9400f); print(student.speak()); print(worker.speak()); } private static void print(String speak) { System.out.println(speak); } }
以上是关于11.13 第十二次的主要内容,如果未能解决你的问题,请参考以下文章