什么意思呀?!我比较菜..不明白你的意思,,能说说吗?!

解决方案 »

  1.   

    自定义类的equals方法要自己定义覆盖的,否则默认为==
    所以System.out.println(a.equals(b));等价于System.out.println(a==b);重写覆盖:
    class equalsSample
    {
    int No;
    int Age;
    String Name;
    String Sex;
    equalsSample()
    {
    No=0;
    Name="Liu";
    Sex="male";
    Age=20;
    }
    equalsSample(int a)
    {
    Age=a;
    }
    void showInfo()
    {
    System.out.println("Name: "+Name+'\n'+"No: "+No+'\n'+"Sex: "+Sex+'\n'+"Age: "+Age);
    }
             
             //这是我加的
             boolean equals(equalsSample a, equalsSample b) {
               if (a.No == b.No && a.Age == b.Age &&
                   && a.Name == b.Name && a.Sex == b.Sex) {
                   return true;
               } else {
                   return false;
               }
             } public static void main(String [] args)
    {
    equalsSample a= new equalsSample();
    equalsSample b= new equalsSample();
    a.showInfo();
    b.showInfo();
    System.out.println(a.equals(b));
    }
    }这样应该就可以了。
      

  2.   

    原来是这么回事.谢谢了.我是菜鸟,分不多.见谅