Source of Person.java


  1: /**
  2:  * Root class for a simple inheritanc ehierarchy.
  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:     /** Person requires a name */
 14:     public Person(String n) {
 15:         this.name = n;
 16:     }

 18:     /** return this Person's name */
 19:     public String getName() {
 20:         return this.name;
 21:     }

 23:     /** Change this Person's name */
 24:     public void setName(String nn) {
 25:         this.name = nn;
 26:     }

 28:     /** A method for children classes to inherit */
 29:     public void publicPersonMethod() {
 30:         System.out.println("\tin publicPersonMethod for " + this.name);
 31:     }

 33:     /** A method for children classes to inherit */
 34:     public void callingPrivatePersonMethod() {
 35:         System.out.println("\tin callingPrivatePersonMethod for " + this.name);
 36:         privatePersonMethod();
 37:         System.out.println("\tcallingPrivatePersonMethod done");
 38:     }

 40:     /** A method children classes can't call *directly* */
 41:     private void privatePersonMethod() {
 42:         System.out.println("\t\tin privatePersonMethod for " + this.name);
 43:     }

 45:     /** A method for children classes to replace entirely. */
 46:     public void replacedMethod() {
 47:         System.out.println("\tin replacedMethod for Person " + this.name);
 48:     }

 50:     /** A method for children classes to add to. */
 51:     public void revisedMethod() {
 52:         System.out.println("\tin revisedMethod for Person " + this.name);
 53:     }

 55:     /** A method to represent this Person using a String */
 56:     @Override
 57:     public String toString() {
 58:         return name;
 59:     }

 61: }