当前页面: 开发资料首页 → J2SE 专题 → 大家帮忙看看这个怎么输出。
大家帮忙看看这个怎么输出。
摘要: 大家帮忙看看这个怎么输出。
import java.util.Vector;
import java.util.Iterator;
public class score_table
{
String stu_name;
int stu_chinese;
int stu_math;
int stu_english;
public score_table(String stu_name,int stu_chinese,int stu_math,int stu_english)
{
this.stu_name = stu_name;
this.stu_chinese = stu_chinese;
this.stu_math = stu_math;
this.stu_english = stu_english;
}
public static void main(String args[])
{
Vector stu = new Vector();
stu.add(new score_table("Jacky",78,82,76));
//stu.add("dfdf");
Iterator it = stu.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
}
}
现在输出是:Test4@35ce36
我想让他输出我原来输入的值Jacky 78 82 76,应该怎么弄啊?
写一个toString方法
public String toString()
{
return this.stu_name+" "+this.stu_chinese+" "+this.stu_math+" "+this.stu_english;
}
因为你没有重写toString方法,所以它默认调用的是Object的toString方法,这个默认实现的方法默认返回的是对象的hash散列值,就是你看到的结果
给score_table类写一个toString()方法
非常感谢~