Source of SpeciesEqualsDemo.java


  1: //SpeciesEqualsDemo.java
  2: 
  3: public class SpeciesEqualsDemo
  4: {
  5:     public static void main(String[] args)
  6:     {
  7:         Species s1 = new Species(), s2 = new Species();
  8:         s1.setSpecies("Klingon ox", 10, 15);
  9:         s2.setSpecies("Klingon ox", 10, 15);
 10: 
 11:         if (s1 == s2)
 12:             System.out.println("Match with ==.");
 13:         else
 14:             System.out.println("Do Not match with ==.");
 15: 
 16:         if (s1.equals(s2))
 17:             System.out.println("Match with the method equals.");
 18:         else
 19:             System.out.println("Do Not match with the method equals.");
 20: 
 21:         System.out.println("Now change one Klingon ox to lowercase.");
 22:         s2.setSpecies("klingon ox", 10, 15); //Use lowercase
 23: 
 24:         if (s1.equals(s2))
 25:             System.out.println("Match with the method equals.");
 26:         else
 27:             System.out.println("Do Not match with the method equals.");
 28:     }
 29: }