62,614
社区成员
发帖
与我相关
我的任务
分享
public class weatherInfo{
public String time ;
public int light;
public void setTime(String text)
{
this.time=text;
}
public void setLight(String text)
{
this.light=Integer.parseInt(text);;
}
public String getTime()
{
return time;
}
public int getLight()
{
return light;
}
public String getTimeLight()
{
String information = "时间" + time + "\n"
+"亮度"+ light + "\n" ;
return information;
}
}
package my;
public class test1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
test t=new test();
t.setLight("456");
t.setTime("123");
t.getLight();
t.getTimeLight();
System.out.println(t);
}
}
在你的类中添加:@Override
public String toString() {
return "test [time=" + time + ", light=" + light + "]";
}
测试正常。不知道你是什么问题。