2266: 抽象类-Person类
金币值:2
定数:6
时间限制:1.000 s
内存限制:128 M
正确:0
提交:0
正确率:0.00% 命题人:
题目描述
定义一个抽象类Person,然后定义它的子类Student和Teacher。
import java.util.Scanner; public class Main { public static void main(String[] args) { String name; Scanner in = new Scanner(System.in); name = in.nextLine(); doIntroduction(new Student(name)); doIntroduction(new Teacher(name)); in.close(); } public static void doIntroduction(Person p){ p.introduction(); } } /*以下为你的代码*/
输入格式
输入1行:姓名
输出格式
见样例
输入样例 复制
小明
输出样例 复制
小明是一个学生
小明是一个老师