Question test = new Question();
useranswer = Integer.parseInt(JOptionPane.showInputDialog(null,
"What is the Result?" + "\n" + test.toString() ));
问题类中的toString
public String toSting() {
return "" + firstNum + " " + operator + " " + secondNum + " = ";
}
为什么我得到“getClass()。getName()+'@'+ Integer.toHexString(hashCode())”我的问题类调用toString而不是my overriden toString()的格式?
答案 0 :(得分:8)
toSting()
与toString()
不同。
@Override
注释。如,
@Override // don't forget this!
public String toString() {
// code that returns a String
}