java 判定是否为同一种事物

package com.kong;

public class staticDemo05 {
  public static void main(String[] args)
  {
    new staticDemo05().fun();

  }
  public void fun()
  {
    System.out.println("你好,世界!");
  }
}

 

=============================================================//分割线

package com.kong;

 


public class Aila {

  String name;
  int age;
  public Aila(String name,int age)
  {
    this.name=name;
    this.age=age;
  }

  public boolean compare(Aila aila)
  {
    if(this.name.equals(aila.name) && this.age==aila.age)
      return true;
    else
      return false;

  }

  public String getName()
  { 
    return this.name;
  }

  public int GetAge()
  {
    return this.age;

  }

  public static void main(String args[])
  {
    Aila aila1=new Aila("Tom",2);
    Aila aila2=new Aila("Tom",2);
   if (aila1.compare(aila2))
  {
    System.out.println("是同一只猫。");
  }
}
}

 

 

 

 

posted @ 2017-11-20 12:11  妮蔻的绯闻男友  阅读(499)  评论(0编辑  收藏  举报