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基础案例4-4学生和老师
最新推荐文章于 2023-07-03 09:47:41 发布