java基础案例4-4学生和老师

package com.itheima;
import java.util.Scanner;

abstract class Person{
    void speak(){}
}

class Teacher extends Person{
    private String name;
    void setName(String name){
        this.name = name;
    }
    String getName(){
        return name;
    }
    void speak(){
        System.out.println("这道题怎么写");
    }
}

class Student extends Person{
    private String name;
    void setName(String name)
    {
        this.name = name;
    }
    String getName(){
        return name;
    }
    void speak(){
        System.out.println("不会");
    }
}

public class Main{
    public static void main(String[] args)
    {
        Teacher teacher = new Teacher();
        Student student = new Student();
        teacher.setName("老王");
        Scanner in = new Scanner(System.in);
        String choose = in.next();
        student.setName(choose);
        System.out.println(teacher.getName() + "向"+student.getName()+"提问");
        System.out.print(teacher.getName()+"说:");
        teacher.speak();
        System.out.print(student.getName()+"说:");
        student.speak();
    }
}

你可能感兴趣的:(面试,学习路线,阿里巴巴,java,开发语言,后端,面试)