2025年JAVA类的继承Cadre—Teacher—Teacher_Cadre

JAVA类的继承Cadre—Teacher—Teacher_CadreJAVA 类的继承 Cadre Teacher Teacher Cadre 分别定义 Teacher 教师 类和 Cadre 干部 类 采用多重继承方式由这两个类派生出新类 Teacher Cadre 教师兼干部 要求 1 在两个基类中都包含姓名 年龄 性别 地址 电话等数据成员 2 在 Teacher 类中还包含数据成员 title 职称 在 Cadre 类中还包含数据成员

大家好,我是讯享网,很高兴认识大家。

JAVA类的继承Cadre—Teacher—Teacher_Cadre

分别定义Teacher(教师)类和 Cadre(干部)类,采用多重继承方式由这两个类派生出新类Teacher__Cadre(教师兼干部)。
要求
1.在两个基类中都包含姓名、年龄、性别、地址、电话等数据成员。
2.在Teacher类中还包含数据成员 title(职称),在 Cadre类中还包含数据成员 post(职务),在Teacher_Cadre类中还包含数据成员 wages(工资)。
3.对两个基类中的姓名、年龄、性别、地址、电话等数据成员用相同的名字,在引用这些数据成员时,指定作用域。
4.在类体中声明成员函数,在类外定义成员函数。
5.在派生类Teacher_Cadre 的成员函数show中调用Teacher类中的display 函数,输出姓名、年龄、性别、职称、地址、电话,然后再用输出职务与工资。
输入

Wang-li 50 f prof. president 135 Beijing Road,Shanghai (021) 1534.5 

讯享网

输出


讯享网

讯享网name:Wang-li age:50 sex:f title:prof. address:135 Beijing Road,Shanghai tel:(021) post:president wages:1534.5 

代码

import org.omg.PortableInterceptor.INACTIVE; import java.util.Scanner; class Cadre{ 
    protected String post; public Cadre(String post){ 
    this.post=post; } } class Teacher extends Cadre{ 
    protected String name; protected String age; protected String sex; protected String title; protected String address; protected String tel; public Teacher(String name,String age,String sex,String title,String address,String tel,String post){ 
    super(post); this.name=name; this.age=age; this.title=title; this.sex=sex; this.address=address; this.tel=tel; } } class Teacher_Cadre extends Teacher{ 
    protected String wages; public Teacher_Cadre(String name,String age,String sex,String title,String address,String tel,String post,String wages){ 
    super(name,age,sex,title,address,tel,post); this.wages=wages; } public void display(){ 
    System.out.println("name:"+name); System.out.println("age:"+age); System.out.println("sex:"+sex); System.out.println("title:"+title); System.out.println("address:"+address); System.out.println("tel:"+tel); System.out.println("post:"+post); System.out.println("wages:"+wages); } } public class Main { 
    public static void main(String[] args) { 
    Scanner sc = new Scanner(System.in); String strName = sc.nextLine(); String strAge =sc.nextLine(); String strSex = sc.nextLine(); String strTitle =sc.nextLine(); String strPost = sc.nextLine(); String strAddress =sc.nextLine(); String strTel = sc.nextLine(); String strWages = sc.nextLine(); //Cadre cadre = new Cadre(strPost); //Teacher teacher=new Teacher(strName,strAge,strSex,strTitle,strAddress,strTel,strPost); Teacher_Cadre teacher_cadre=new Teacher_Cadre(strName,strAge,strSex,strTitle,strAddress,strTel,strPost,strWages); teacher_cadre.display(); } } 
小讯
上一篇 2025-02-25 08:25
下一篇 2025-01-27 11:13

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/125216.html