import java.util.*;
class Person
{
private String name;
private int age;
Person(String name,int age)
{
this.name=name;
this.age=age;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
class ArrayTest2
{
public static void main(String[] args)
{
ArrayList al=new ArrayList();
al.add(new Person("li01",30));
al.add(new Person("li02",31));
al.add(new Person("li02",31));
sop(al);//输出结果是[Person@9931f5, Person@19ee1ac, Person@1f1fba0]
al.add("li01");
al.add("li02");
al.add("li03");
sop(al);//输出结果是 [li01, li02, li03]
public static void sop(Object obj)
{
System.out.println(obj);
}
}
同样都是对象为什么输出结果不同
|
|