gpt4 book ai didi

java - 为什么我的 getName() 和 getSalary() 会导致错误?他们不应该从其他类(class)拉出来吗?

转载 作者:行者123 更新时间:2023-12-03 18:08:19 25 4
gpt4 key购买 nike

我出现的唯一错误是在该类中找不到 getName() 和 getSalary()。我正在尝试获取输入到 testEmployee 类中的信息以使用 Employee 并显示结果。我收到构建成功消息但没有输出。

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());
}
}

最佳答案

您需要 emp1.getName()emp1.getSalary() 而不是 getName()getSalary( )main

中的 println 函数中

关于java - 为什么我的 getName() 和 getSalary() 会导致错误?他们不应该从其他类(class)拉出来吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17750660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com