LimWei  

Variables defined at the class level:  

  (a) Instance variables.

  (b) Class variables.

     static variables

Constructure:

Methods:

Regular methods:

Class methods:

  1.   also called Static method
  2.   An instance method can reference a class variable (or call a class method),
  3.   A class method cannot access an instance variable or call an instance method directly

Equals:

  1.  In Java, "==" means identity equality.
  2.  If we want to use the equals method, we must call it by name.
  3.  All classes are descendants of class Object, and if they don't define their own equals or inherit one from elsewhere, they will inherit an equals method from class Object. It simply checks identity equality.

  Ie.

  @Override
  public boolean equals(Object obj) {

    return ture or false;

  }

  Ex.

   /**
  * Returns true iff this Monster is equivalent to obj, meaning that
  * they have the same name and size, and equivalent belly contents.
  *
  * @param obj the Object to be compared to.
  * @return true iff this Monster is equivalent to obj.
  */
  @Override
  public boolean equals(Object obj) {
    // This check allows a ver efficient answer in the case where the
    // we more than equivalence, we have identity equality.
    // That is, we are comparing the very same object to itself.
    if (this == obj)
      return true;
    // This check avoids null references later on.
    if (obj == null)
      return false;
    // If the two objects aren't even instances of the same class, they
    // certainly aren't equivalent.
    if (getClass() != obj.getClass())
      return false;
    // We are comparing two Monster objects. We must cast obj from its
    // declared type (Object) to Monster so that Java will know it has
    // Monster-specific attributes, like belly.
      Monster other = (Monster) obj;
    // Now we can check the attributes for equivalence.
    // We can't check name equality until we are sure we are comparing
    // two non-null Strings.
    if (this.name == null) {
      if (other.name != null) {
        return false;
      }
    } else if (!this.name.equals(other.name)) {
      return false;
    } else if (this.size != other.size) {
      return false;
    } else if (!Arrays.equals(this.belly, other.belly)) {
    // Arrays.equals is true iff the two arrays have the same length,
    // and each pair of their elements at corresponding positions
    // are equals.
      return false;
    }
    return true;
  }

 

posted on 2018-02-04 09:19  LimWei  阅读(77)  评论(0)    收藏  举报