【Java】定义一个People类,用来描述人的属性和行为,学生包括姓名、籍贯、年龄。
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();
}
}