- class TestStudent {
- public static void main(String[] args) {
- Student s = new BaseStudent();
- s.study();
- s.setName("赵四");
- }
- //public static void getStudent(Student s)
- }
- abstract class Student {
- private String name;
- private int age;
- public Student() {}
- public Student(String name,int age) {
- this.name = name;
- this.age = age;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getName() {
- return name;
- }
- public void setAge(int age) {
- this.age = age;
- }
- public int getAge() {
- return age;
- }
- abstract public void study();
- }
- class BaseStudent extends Student {
- public BaseStudent() {}
- public BaseStudent(String name,int age) {
- super(name,age);
- }
- public void study() {
- System.out.println("java基础课程");
- }
- }
- class JobStudent extends Student{
- public JobStudent() {}
- public JobStudent(String name,int age) {
- super(name,age);
- }
- public void study() {
- System.out.println("安卓课程");
- }
- }
复制代码 |
|