赞
踩
定义一个People类,用来描述人的属性和行为,学生包括姓名、籍贯、年龄。用Display函数显示人的信息。然后定义一个从People类继承的子类Student,表示学生,包括学号、年级排名,和另一个从People类继承的子类Master,表示学生的导师信息,包括职工号、研究方向、学生信息,并能够显示导师的信息。
要求包括构造函数。
package com.company; class people{ private String name; private Integer age; private String address; public people(String name, Integer age,String address){ System.out.println(name); this.name = name; this.age = age; this.address=address; } public people(String name){ this.name = name; new people(name, age,address); } public void display(){} } class teacher extends people{ public teacher(String name){ super(name); } private String name=new String("Y老师"); private Integer age=35; private String address=new String("H省"); private String number=new String("2019"); private String study=new String("Java"); private String stu=new String("阿然"); public void display(){ System.out.println("姓名:"+name); System.out.println("年龄:"+age); System.out.println("籍贯:"+address); System.out.println("职工号:"+number); System.out.println("研究方向:"+study); System.out.println("学生:"+stu); } } class Student extends people{ public Student(String name){ super(name); } private String name=new String("阿然"); private Integer age=21; private String address=new String("N省"); private String number=new String("2016"); private String ranking=new String("17"); public void display(){ System.out.println("姓名:"+name); System.out.println("年龄:"+age); System.out.println("籍贯:"+address); System.out.println("学号:"+number); System.out.println("排名:"+ranking); } } class main { public static void main(String[] args) { Student s = new Student("————————学生信息————————"); s.display(); teacher t = new teacher("————————老师信息————————"); t.display(); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。