为什么我的getName()和getSalary()导致错误?他们不应该从其他班级拉出来吗?

use*_*946 2 java

我出现的唯一错误是在那个类中找不到getName()和getSalary().我试图获取输入testEmployee类的信息以使用Employee并显示结果.我收到Build Successful消息但没有输出.

public abstract class Person {

    // Variables
    private String name;
    private String ssn = null;

    public Person(String name) {
        this.name = name;
    }

    // Pass data to the object Person
    /**
     * 
     * @param ssn
     */
    public void setSsn(String ssn) {
        this.ssn = ssn;
    }

    public String getSsn() {
        return ssn;
    }

    /**
     * 
     * @return
     */
    public abstract String getName();

}

class Employee extends Person {

    // Variables
    private String jobTitle;
    private double salary;
    private String getName;
    private double cost;

    public Employee(String name) {
        super(name);

        salary = 0;
        jobTitle = null;

    }

    // Pass values to the obljects
    // Setters
    public void setJobTitle(String jobTitle) {
        this.jobTitle = jobTitle;
    }

    public void setSalary(double cost) {
        salary = cost;
    }

    // Getters
    @Override
    public String getName() {
        return getName();
    }

    public String getTitle() {
        return getJobTitle();
    }

    public double getSalary() {
        return salary;
    }

    /**
     * @return the jobTitle
     */
    public String getJobTitle() {
        return jobTitle;
    }

    /**
     * @return the getName
     */
    public String getGetName() {
        return getName;
    }

    /**
     * @param getName
     *            the getName to set
     */
    public void setGetName(String getName) {
        this.getName = getName;
    }

    /**
     * @return the cost
     */
    public double getCost() {
        return cost;
    }

    /**
     * @param cost
     *            the cost to set
     */
    public void setCost(double cost) {
        this.cost = cost;
    }
}

public class testEmployee {

    public static void main(String[] args) {
        Employee emp1 = new Employee("John Smith");
        String ssn = "333224444";
        String jobTitle = "Web Designer";
        double cost = 60000;
        System.out.println("Employee " + getName() "\n The current compensation is " + getSalary());
    }
}
Run Code Online (Sandbox Code Playgroud)

nwa*_*lsh 7

你需要有emp1.getName()emp1.getSalary(),而不是getName()getSalary()你的println函数main