java作业求解
1、抽象类People:属性name,抽象方法speak(Strings),构造方法People(Stringname);2、类Student继承People类,添加属性...
1、抽象类People:属性name,抽象方法speak(String s),构造方法People(String name);
2、类Student继承People类,添加属性stunumber,添加构造方法Student(String number,String name),实现Speak方法,输出参数S,然后输出“我是学生”,然后输出“我的学号是:”+stunumber,然后输出“我的姓名是:”+name;
3、类Teacher继承People类,添加属性teanumber,添加构造方法Teacher(String number,String name)实现Speak方法,输出参数S,然后输出“我是老师”然后输出“我的员工号是:”+teanumber,然后输出“我的姓名是:”+name;
4、在main函数中,首先用People申明一个变量p,然后用Student类实现一个对象实例,使用你的学号和姓名构造该对象实例,并把这个对象实例赋值给p,然后调用p.speak("你好")。然后用Teacher类实现一个对象实例,使用"12345"作为员工号和"张三"作为姓名构造该对象实例,并把这个对象实例赋值给p,然后调用p.speak("您好")。 展开
2、类Student继承People类,添加属性stunumber,添加构造方法Student(String number,String name),实现Speak方法,输出参数S,然后输出“我是学生”,然后输出“我的学号是:”+stunumber,然后输出“我的姓名是:”+name;
3、类Teacher继承People类,添加属性teanumber,添加构造方法Teacher(String number,String name)实现Speak方法,输出参数S,然后输出“我是老师”然后输出“我的员工号是:”+teanumber,然后输出“我的姓名是:”+name;
4、在main函数中,首先用People申明一个变量p,然后用Student类实现一个对象实例,使用你的学号和姓名构造该对象实例,并把这个对象实例赋值给p,然后调用p.speak("你好")。然后用Teacher类实现一个对象实例,使用"12345"作为员工号和"张三"作为姓名构造该对象实例,并把这个对象实例赋值给p,然后调用p.speak("您好")。 展开
展开全部
public class Test40031 {//测试类
public static void main(String[] args) {
People p = null;
p = new Student("001", "Zhang San");//学号001, 姓名zhang san
p.speak("你好");
p = new Teacher("12345", "张三");//老师类实例化
p.speak("你好");
}
}
abstract class People{//抽象类People
protected String name;
protected abstract void speak(String s);
public People(String name){
this.name = name;
}
}
class Student extends People{//学生类
private String stunumber;
public Student(String number, String name){
super(name);
this.stunumber = number;
}
public void speak(String s) {
System.out.println(s);
System.out.println("我是学生");
System.out.println("我的学号是: " + stunumber);
System.out.println("我的姓名是: " + super.name);
}
}
class Teacher extends People{//教师类
private String teanumber;
public Teacher(String number,String name){
super(name);
this.teanumber = number;
}
public void speak(String s){
System.out.println(s);
System.out.println("我是老师");
System.out.println("我的员工号是: " + teanumber);
System.out.println("M我的姓名是: " + super.name);
}
}
public static void main(String[] args) {
People p = null;
p = new Student("001", "Zhang San");//学号001, 姓名zhang san
p.speak("你好");
p = new Teacher("12345", "张三");//老师类实例化
p.speak("你好");
}
}
abstract class People{//抽象类People
protected String name;
protected abstract void speak(String s);
public People(String name){
this.name = name;
}
}
class Student extends People{//学生类
private String stunumber;
public Student(String number, String name){
super(name);
this.stunumber = number;
}
public void speak(String s) {
System.out.println(s);
System.out.println("我是学生");
System.out.println("我的学号是: " + stunumber);
System.out.println("我的姓名是: " + super.name);
}
}
class Teacher extends People{//教师类
private String teanumber;
public Teacher(String number,String name){
super(name);
this.teanumber = number;
}
public void speak(String s){
System.out.println(s);
System.out.println("我是老师");
System.out.println("我的员工号是: " + teanumber);
System.out.println("M我的姓名是: " + super.name);
}
}
展开全部
抽象类People:
public abstract class People {
public String name;
public abstract void speak(String s);
public People(String name){
this.name = name;
};
}
实体类Student:
public class Student extends People {
private String stu_num;
public Student(String name) {
super(name);
}
public Student(String stu_num, String name) {
this(name);
this.stu_num = stu_num;
}
@Override
public void speak(String s) {
System.out.println(s);
System.out.println("我是学生。");
System.out.println("我的学号是:" + stu_num);
System.out.println("我的姓名是:" + name);
}
}
实体类teacher:
public class Teacher extends People {
private String tea_num;
public Teacher(String name) {
super(name);
}
public Teacher(String tea_num, String name) {
this(name);
this.tea_num = tea_num;
}
@Override
public void speak(String s) {
System.out.println(s);
System.out.println("我是老师。");
System.out.println("我的员工号是:" + tea_num);
System.out.println("我的姓名是:" + name);
}
public static void main(String[] args) {
People p = new Student("XS001","Jack");
p.speak("您好");
p = new Teacher("12345","张三");
p.speak("你好");
}
}
=============================
运行结果:
您好
我是学生。
我的学号是:XS001
我的姓名是:Jack
你好
我是老师。
我的员工号是:12345
我的姓名是:张三
public abstract class People {
public String name;
public abstract void speak(String s);
public People(String name){
this.name = name;
};
}
实体类Student:
public class Student extends People {
private String stu_num;
public Student(String name) {
super(name);
}
public Student(String stu_num, String name) {
this(name);
this.stu_num = stu_num;
}
@Override
public void speak(String s) {
System.out.println(s);
System.out.println("我是学生。");
System.out.println("我的学号是:" + stu_num);
System.out.println("我的姓名是:" + name);
}
}
实体类teacher:
public class Teacher extends People {
private String tea_num;
public Teacher(String name) {
super(name);
}
public Teacher(String tea_num, String name) {
this(name);
this.tea_num = tea_num;
}
@Override
public void speak(String s) {
System.out.println(s);
System.out.println("我是老师。");
System.out.println("我的员工号是:" + tea_num);
System.out.println("我的姓名是:" + name);
}
public static void main(String[] args) {
People p = new Student("XS001","Jack");
p.speak("您好");
p = new Teacher("12345","张三");
p.speak("你好");
}
}
=============================
运行结果:
您好
我是学生。
我的学号是:XS001
我的姓名是:Jack
你好
我是老师。
我的员工号是:12345
我的姓名是:张三
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询