| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 859 人关注过本帖
标题:有谁会这个?
只看楼主 加入收藏
amymeng
Rank: 1
来 自:青岛
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-11-13
结帖率:0
收藏
已结贴  问题点数:20 回复次数:6 
有谁会这个?
定义一个Person类,含:姓名、性别、年龄等字段;继承Person类设计Teacher类,增加:职称、部门等字段;继承Person类设计Student类,增加:学号、入学时间、专业等字段。定义各类的构造方法和toString()方法,并分别创建对象进行测试。
搜索更多相关主题的帖子: 设计 继承 职称 
2011-11-28 14:47
JeffLi
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:39
专家分:116
注 册:2011-11-18
收藏
得分:10 
操作你已介绍的够详细的了...一步一步来就行...
这个...不会是作业吧..

我的企鹅:67567840
2011-11-29 10:53
xiayizhanzyf
Rank: 2
等 级:论坛游民
帖 子:80
专家分:78
注 册:2010-7-21
收藏
得分:10 
import java.util.Date;
//import java.util.GregorianCalendar;

public class School{
    public static void main(String[] args){
        Person person = new Person("张三", "男", 25);
        Teacher teacher = new Teacher("张兰", "女", 24, "讲师", "英语");
        Student student = new Student("李四", "男", 23, "1001", 2011, 11, 29, "计算机");
        System.out.println(person.toString());
        System.out.println(teacher.toString());
        System.out.println(student.toString());
    }
}

class Person{
    public Person(String na, String s, int a){
        name = na;
        sex = s;
        age = a;
    }
    public String toString(){
        return "name:"+name+"  "+"sex:"+sex+"  "+"age:"+age+"";
    }
    private String name;
    private String sex;
    private int age;
}

class Teacher extends Person{
    public Teacher(String na, String s, int a, String zc, String de){
        super(na, s, a);
        zhicheng = zc;
        department = de;        
    }
    public String toString(){
        return ""+super.toString()+"  "+"zhicheng:"+zhicheng+"  "+"department:"+department+"";
    }
    private String zhicheng;
    private String department;
}

class Student extends Person{
    public Student(String na, String s, int a, String n, int year, int month, int day,  String ma){
        super(na, s, a);
        no = n;
        time = new Date(year, month, day);
        major = ma;        
    }
    public String toString(){
        return ""+super.toString()+"  "+"no:"+no+"  "+"time:"+time+"  "+"major:"+major+"";
    }
    private String no;
    private Date time;
    private String major;
}
写的仓促,仅供参考!
2011-11-29 14:25
xiayizhanzyf
Rank: 2
等 级:论坛游民
帖 子:80
专家分:78
注 册:2010-7-21
收藏
得分:0 
该Date构造方法已过时,所以改写了一下
import java.util.Date;
import java.util.GregorianCalendar;

public class School{
    public static void main(String[] args){
        Person person = new Person("张三", "男", 25);
        Teacher teacher = new Teacher("张兰", "女", 24, "讲师", "英语");
        Student student = new Student("李四", "男", 23, "1001", 2011, 11, 29, "计算机");
        System.out.println(person.toString());
        System.out.println(teacher.toString());
        System.out.println(student.toString());
    }
}

class Person{
    public Person(String na, String s, int a){
        name = na;
        sex = s;
        age = a;
    }
    public String toString(){
        return "name:"+name+"  "+"sex:"+sex+"  "+"age:"+age+"";
    }
    private String name;
    private String sex;
    private int age;
}

class Teacher extends Person{
    public Teacher(String na, String s, int a, String zc, String de){
        super(na, s, a);
        zhicheng = zc;
        department = de;        
    }
    public String toString(){
        return ""+super.toString()+"  "+"zhicheng:"+zhicheng+"  "+"department:"+department+"";
    }
    private String zhicheng;
    private String department;
}

class Student extends Person{
    public Student(String na, String s, int a, String n, int year, int month, int day,  String ma){
        super(na, s, a);
        no = n;
        GregorianCalendar calendar = new GregorianCalendar(year, month, day);
        time = calendar.getTime();
        major = ma;        
    }
    public String toString(){
        return ""+super.toString()+"  "+"no:"+no+"  "+"time:"+time+"  "+"major:"+major+"";
    }
    private String no;
    private Date time;
    private String major;
}
2011-11-29 14:35
一水半沙
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-1-9
收藏
得分:0 
看着怪吓人的...
2012-01-09 19:57
Abiosis
Rank: 2
等 级:论坛游民
帖 子:13
专家分:33
注 册:2012-1-12
收藏
得分:0 
这个是基础吧      java书上里完全有    思路说的很详细   只需要定义相关的类   该继承继承就行了
2012-01-12 10:40
as584520
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-1-31
收藏
得分:0 
2012-01-31 16:50
快速回复:有谁会这个?
数据加载中...
 
   



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

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