为什么Book的输出显示为参考?

时间:2019-02-06 02:09:20

标签: java arraylist collections

为什么Book类型的数组列表的输出显示为对象引用,而String类型的ArrayList的输出显示为A,B,C?

Book b1=new Book(101,"Let us C","Yashwant Kanetkar","BPB",8);  
Book b2=new Book(102,"Data Communications & Networking","Forouzan","Mc Graw Hill",4);  
Book b3=new Book(103,"Operating System","Galvin","Wiley",6);  

list.add(b1);  
list.add(b2);  
list.add(b3);  

for(Book b:list){  
System.out.println(b); 

String A = new String("A");
String B = new String("B");
String C = new String("C");
String d = new String("D");
String e = new String("E");
ArrayList<String> aall = new ArrayList<String>();
aall.add(A);
aall.add(B);
aall.add(C);
aall.add(d);
aall.add(e);
for(String o:aall)
{
    System.out.println(o);
}

示例输出:

Books$Book@4e25154f
A
B
C
D
E
Books$Book@70dea4e
A
B
C
D
E
Books$Book@5c647e05
A
B
C
D
E

0 个答案:

没有答案