0

父类是...

public class UMember {
    private String first;
    private String last;
    private String street;
    private String city;
    private String state;
    private String zipcode;

    public UMember() {
        this("na", "na", "na", "na", "na", "na");
    }

    public UMember(String first, String last, String street, 
            String city, String state, String zipcode){
        set(first, last, street, city, state, zipcode);
    }

    private void set(String first, String last, String street, 
            String city, String state, String zipcode){
        this.first = first;
        this.last = last;
        this.street = street;
        this.city = city;
        this.state = state;
        this.zipcode = zipcode;
    }

    public void setUMember(String first, String last, String street,
            String city, String state, String zipcode) {
       set(first, last, street, city, state, zipcode);
    }

UMember 的父子类是...

public class Employee extends UMember {
    private int eid;
    private String doh;
    private String dept;
    private double salary;

    public Employee() {
        this(0, "na", "na", 0.0, "na", "na", "na", "na", "na", "na");
    }

    public Employee(int eid, String doh, String dept, double salary) {
        this(eid, doh, dept, salary, "na", "na", "na", "na", "na", "na");
    }



    public Employee(int eid, String doh, String dept, double salary, 
            String first, String last, String street, String city, 
            String state, String zipcode) {
        super(first, last, street, city, state, zipcode);
        set(eid, doh, dept, salary);
    }

    private void set(int eid, String doh, String dept, double salary) {
        this.setEid(eid);
        this.setDoh(doh);
        this.setDept(dept);
        this.setSalary(salary);
    }

    private void setEmployee(int eid, String doh, String dept, double salary, 
            String first, String last, String street, String city, 
            String state, String zipcode) {
        setUMember(first, last, street, city, state, zipcode);
        set(eid, doh, dept, salary);
    }

Employee 的子类是...

public class Faculty extends Employee{
    private String rank;
    private int annualTeachingLoad;

    public Faculty() {
        this("na", 0, 0, "na", "na", 0.0, 
                "na", "na", "na", "na", "na", "na");
    }

    public Faculty(String rank, int annualTeachingLoad) {
        this(rank, annualTeachingLoad, 0, "na", "na", 0.0, 
                "na", "na", "na", "na", "na", "na");
    }

上面的 Faculty 子类中的默认构造函数都不正确。我不知道为什么。我首先使用 Faculty 的默认值,然后是 Employee,最后是 UMember。任何关于为什么这两段代码都不正确的帮助将不胜感激。

4

1 回答 1

2

this您正在使用而不是调用构造函数super。调用构造函数 withthis只能调用在同一个类中声明的构造函数,而superis 用于调用超类中的构造函数。

于 2013-10-02T02:55:09.943 回答