您的位置:首页 > 移动开发 > Objective-C

Object类中toString方法

2014-01-08 11:16 609 查看
/*public class ToStringMethod
{
String str;
int age;
public static void main(String args[])
{
ToStringMethod train=new ToStringMethod();
System.out.println(train);
}
}*/
public class ToStringMethod
{
String str;
int age;
public String toString()
{
return ("My name is "+this.str);
}
public static void main(String args[])
{
ToStringMethod train=new ToStringMethod();
System.out.println(train);
}
}
直接打印引用时。会调用其toString()方法,这一点必须注意!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: