mw43のプロフィール

@mw43 mw43
ありがとう数2
質問数2
回答数1
ベストアンサー数
0
ベストアンサー率
0%
お礼率
75%

  • 登録日2008/06/08
  • toStringメソッドについて

    java言語超初心者です。以下のコードを入力しました。 class MyCls1 { String name; int count; public void look() { System.out.println("名前" + name + "個数" + count); } } class MyCls2 { String name; int count; public void look() { System.out.println("なまえ" + name + "こすう" + count); } public String toString() { String str = "MyCls2:name = " + name + "count=" + count; return str; } } public class JaCls06 { public static void main(String args[]) { MyCls1 bbb = new MyCls1(); bbb.name = "AAA"; bbb.count = 111; bbb.look(); System.out.println(bbb); MyCls2 dd = new MyCls2(); dd.name = "BBB"; dd.count = 2222; dd.look(); System.out.println(dd); String ee; ee = dd.toString(); System.out.println(ee); } } 実行結果が 名前AAA個数111 MyCls1@19821f なまえBBBこすう2222 MyCls2:name = BBBcount=2222 MyCls2:name = BBBcount=2222 なんですが、2行目以降の結果がどの行を反映して出てきたのかが全くわかりません。どうか、教えてください。初歩的な質問で申し訳ないです。