/** * This class will improve human by some methods * defined by the object-class. * * This methods are equals(..) and toString(). * * Also, it will use the access modifiers mentioned by Björn. * * @author mario */ public class Human2 { private String name; /** * Define a custom constructor, taking the name of the human * * @param name the name of the student */ public Human2(String name) { // set the name attribute this.name = name; } /** * This method will return a string representation * of the human. */ @Override public String toString() { // create the string to be returned return "Human: \""+this.name+"\""; } /** * This method will return true if the objects are identical. * Otherwise it will return false. */ @Override public boolean equals(Object obj) { // check for an empty object if( obj == null ) { // comparison is not possible return false; } // look if the object is of the same type as the current object if( obj instanceof Human2 ) { // convert the object to a master student Human2 other = (Human2)obj; // check for equal variables return other.name.equals(this.name); } else { // not the same type so no equal objects return false; } // unreachable code } }