Source of Person.java


  1: /**
  2:  * Root class for a simple inheritance hierarchy.
  3:  * This class has both public and private methods.
  4:  * Student extends this class.
  5:  *
  6:  * @author Mark Young (A00000000)
  7:  */
  8: public class Person {

 10:     /** Every Person has a name */
 11:     private String name;

 13:     /** 
 14:      * Person requires a name
 15:      *
 16:      * @param name the Person's name
 17:      */
 18:     public Person(String name) {
 19:         this.name = name;
 20:     }

 22:     /** 
 23:      * Return this Person's name 
 24:      *
 25:      * @return this Person's name
 26:      */
 27:     public String getName() {
 28:         return this.name;
 29:     }

 31:     /** 
 32:      * Change this Person's name 
 33:      *
 34:      * @param newName this Person's new name
 35:      */
 36:     public void setName(String newName) {
 37:         this.name = newName;
 38:     }

 40:     /** 
 41:      * A method for children classes to inherit 
 42:      */
 43:     public void publicPersonMethod() {
 44:         System.out.println("\tin publicPersonMethod for " + this.name);
 45:     }

 47:     /** 
 48:      * A method for children classes to inherit 
 49:      */
 50:     public void callingPrivatePersonMethod() {
 51:         System.out.println("\tin callingPrivatePersonMethod for " + this.name);
 52:         privatePersonMethod();
 53:         System.out.println("\tcallingPrivatePersonMethod done");
 54:     }

 56:     /** 
 57:      * A method children classes can't call *directly* 
 58:      */
 59:     private void privatePersonMethod() {
 60:         System.out.println("\t\tin privatePersonMethod for " + this.name);
 61:     }

 63:     /** 
 64:      * A method for children classes to replace entirely. 
 65:      */
 66:     public void replacedMethod() {
 67:         System.out.println("\tin replacedMethod for Person " + this.name);
 68:     }

 70:     /** 
 71:      * A method for children classes to add to. 
 72:      */
 73:     public void revisedMethod() {
 74:         System.out.println("\tin revisedMethod for Person " + this.name);
 75:     }

 77:     /** 
 78:      * A method to represent this Person using a String 
 79:      *
 80:      * @return a String representing this Person
 81:      */
 82:     @Override
 83:     public String toString() {
 84:         return name;
 85:     }

 87: }