| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 745 人关注过本帖
标题:各位帮忙改进下代码
取消只看楼主 加入收藏
Heart→M鹏
Rank: 2
等 级:论坛游民
帖 子:80
专家分:94
注 册:2011-5-13
结帖率:83.33%
收藏
已结贴  问题点数:0 回复次数:1 
各位帮忙改进下代码
程序代码:
public class Demo_9 {
    public static void main(String[] args) {
        Teacher teacher = new Teacher(11111,"张三", "男", 25, "讲师");
        teacher.display();
        Student student = new Student(9922, "李四", "男", 21, "公寓");
        student.display();
    }

}

class Person{
    protected String name;
    protected String sex;
    protected int age;
}

class Teacher extends Person{
    protected int tnumbers;
    protected String title;
    public Teacher(int tnumbers, String name, String sex, int age, String title){
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.tnumbers = tnumbers;
        this.title = title;
    }
    public void display(){
        javax.swing.JOptionPane.showMessageDialog(null,"  职工号  " +tnumbers+ " 名字 " +name
                    + "  性别  " +sex
                    + "  年龄  " +age
                    + "  职称  " +title);
    }
}

class Student extends Person{
    protected int snumbers;
    protected String address;
    public Student(int snumbers, String name, String sex, int age, String address){
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.snumbers = snumbers;
        this.address = address;
    }
    public void display(){
        javax.swing.JOptionPane.showMessageDialog(null," 学号   " +snumbers
                    + " 名字   " +name
                    + "  性别  " +sex
                    + "  年龄  " +age
                    + "  家庭住址  " +address);
    }
}
就是我想把那个display也搞个继承,各位看看是否行得通
搜索更多相关主题的帖子: 公寓 讲师 teacher color 
2011-10-11 09:16
Heart→M鹏
Rank: 2
等 级:论坛游民
帖 子:80
专家分:94
注 册:2011-5-13
收藏
得分:0 
回复 4楼 小恕
谢谢叻,我当时的目的就是想把display写到person里去,但是刚学实在不知道怎么弄,谢谢叻!
2011-10-14 11:27
快速回复:各位帮忙改进下代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017995 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved