class Person { public String name; public String sex; public int age; public Person() { } public Person(String name, int age) { this.name = name; this.age = age; } public void setSex(String sex) { this.sex = sex; } public void print() { System.out.println("姓名:" + this.name + " 性别:" + this.sex + " 年龄:" + this.age); }}public class Student extends Person { public String school; public String department; public String studentno; public Student(String name, int age, String school, String department, String studentno) { super(name, age); this.school = school; this.department = department; this.studentno = studentno; } public void print() { System.out.println("姓名:" + this.name + " 性别:" + this.sex + " 年龄:" + this.age + " 学院:" + this.school + " 系:" + this.department + " 学号:" + this.studentno); } public static void main(String[] args) { Person a = new Person("张三", 24); a.setSex("男"); a.print(); Student b = new Student("李四", 20, "清华大学", "计算机技术", "0828322109"); b.setSex("女"); b.print(); }} 保存成Student.java文扒友件,租此逗执行以下可以看弊卖出效果!
相关文章
-
java 递归法
2023-12-13 01:46 阅读(577) -
JAVA软件开发培训靠谱么?求内幕~
2023-12-11 14:46 阅读(564) -
java Web主要用来做什么的?
2023-11-23 10:59 阅读(621)
1 java中取模%:1%2 和 3%2 结果分别是多少 ?
592 阅读
2 java里extends代表什么
576 阅读
3 java中的StringBuilder有什么用?
575 阅读
4 java 如何打开一个jar包
586 阅读
5 java模拟器
630 阅读