java - Why are my getName() and getSalary() causing errors? Should they not be pulling from the other class? -
the error have showing getname() , getsalary() not found in there class. trying information entered testemployee class use use employee , display results. build successful message no output.
public abstract class person { // variables private string name; private string ssn = null; public person(string name) { this.name = name; } // pass data 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 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 jobtitle */ public string getjobtitle() { return jobtitle; } /** * @return getname */ public string getgetname() { return getname; } /** * @param getname * getname set */ public void setgetname(string getname) { this.getname = getname; } /** * @return cost */ public double getcost() { return cost; } /** * @param cost * cost 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 current compensation " + getsalary()); } }
you need have emp1.getname() , emp1.getsalary() instead of getname() , getsalary() in println function in main
Comments
Post a Comment