📄 testpeople_2.java
字号:
/* File Name:TestPeople_2.java
* 这是关于this与super关键字综合应用的实例,用来说明这两个关键字的用法。
*/
class People {
String Name;
String Num="01";
String Sex;
int Ages;
public String ShowInfo() {
return("姓名:"+Name+" 性别:"+Sex+" 年龄:"+Ages);
}
}
class Student extends People
{
String Num;
String ClassNo;
public String ShowInfo() {
return("学号:"+Num+super.Num+" "+super.ShowInfo()+" 班号:"+ClassNo);
}
}
class Teacher extends People {
String Principalship;
String Department;
public String ShowInfo() {
return(super.ShowInfo()+" 职务:"+Principalship+" 部门:"+Department);
}
}
public class TestPeople_2 {
public static void main(String[] args) {
Student NewPeople=new Student();
NewPeople.Name="周文丽";
NewPeople.Num="1001";
NewPeople.Sex="女";
NewPeople.Ages=22;
NewPeople.ClassNo="教育001";
System.out.println(NewPeople.ShowInfo());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -