Eclipse java不返回具体结果 只出现地址 这个是什么情况

public class whatTime {

public whatTime (int seconds){
String result = "";
int h = seconds / 3600;
int m = (seconds - h*3600)/60;
int s = seconds - h*3600 - m*60;
result = result + h + ":"+ m + ":" + s ;

}
public static void main ( String[] args) {

whatTime wTime = new whatTime(300);
System.out.println(wTime);
}

}

第1个回答  2014-11-15
public class whatTime {
private String result = "";
public whatTime (int seconds){
int h = seconds / 3600;
int m = (seconds - h*3600)/60;
int s = seconds - h*3600 - m*60;
result = result + h + ":"+ m + ":" + s ;
}

public String toString(){
return result;
}

public static void main ( String[] args) {

whatTime wTime = new whatTime(300);
System.out.println(wTime);
}
}

请改成上面代码本回答被提问者采纳
第2个回答  2014-11-15
wTime是一个对象,他有哪些参数你可以调用属性显示,直接显示对象显示的是对象的地址追问

能说的具体点么

追答

你的对象里面肯定有属性吧,其实你要显示的也就是这些属性,你应该是wTime.属性去显示,或者他们说的tostring在实体类中重写也可以,不能直接去打印对象,这样打印出来的是对象的地址

第3个回答  2014-11-15
你要重载toString方法追问

这个怎么能问问怎么重载么。。。

追答

楼下已有人回答了

相似回答