【发布时间】:2015-01-28 21:46:09
【问题描述】:
您好,所以我必须创建一个名为 Employee 的超类。然后是从 Employee2 继承的 CommissionEmployee2 类(人是具有名字、姓氏和 SSN 的员工。并且这种类型的员工赚取佣金)。但是当我运行测试程序时,toStrings 出现格式错误。 P.S 对于复制和粘贴代码的奇怪格式感到抱歉!
//return String representation of Employee Object
public String toString()
{
return String.format("%s: %s %s%n%s: %s%n%s" , "employee" , getFirstName(), getLastName(), "social security number" , getSocialSecurityNumber());
}
}
这是CommissionEmployee2.java中写的toString
//return String representation of CommissionEmployee copied from the book
public String toString()
{
return String.format("%s %s%n%s: %.2f%n%s: %.2f" , "commission employee" , super.toString(), "gross sales" , getGrossSales(), "commission rate" , getCommissionRate());
}
}
【问题讨论】:
-
下一次,一个最小的例子会很好。大部分代码与问题无关
标签: java inheritance syntax formatting hierarchy