java问题,关于toString
麻烦讲解下,不是很理解packagetostring;publicclassTestToString{privateStrings="spring";publicTest...
麻烦讲解下,不是很理解
package tostring;
public class TestToString {
private String s = "spring ";
public TestToString(String str){
this.s = str + this.s;
}
public static void main(String[] args){
TestToString test = new TestToString("hibernate ");
System.out.println(test);
System.out.println(test.s);
}
public String toString(){
this.s = "strus "+this.s;
return s;
}
}
输出结果:
strus hibernate spring
strus hibernate spring 展开
package tostring;
public class TestToString {
private String s = "spring ";
public TestToString(String str){
this.s = str + this.s;
}
public static void main(String[] args){
TestToString test = new TestToString("hibernate ");
System.out.println(test);
System.out.println(test.s);
}
public String toString(){
this.s = "strus "+this.s;
return s;
}
}
输出结果:
strus hibernate spring
strus hibernate spring 展开
3个回答
展开全部
有谈稿源什么不理解,因为重写了toString方含态法,输出test时自敬行动调用toString方法,test.s输出s的值。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-04-18
展开全部
看雀耐执行顺序
public static void main(String[] args){
TestToString test = new TestToString("森岁手hibernate ");
System.out.println(test); -------------- 先
System.out.println(test.s); ------------- 后
}
public String toString(){
this.s = "此嫌strus "+this.s; ---------------------------
return s;
}
public static void main(String[] args){
TestToString test = new TestToString("森岁手hibernate ");
System.out.println(test); -------------- 先
System.out.println(test.s); ------------- 后
}
public String toString(){
this.s = "此嫌strus "+this.s; ---------------------------
return s;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询