大家好,又见面了,我是你们的朋友全栈君。
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();
}
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/151728.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...