public class Person
1: package inheritance;
4: /**
5: * Root class for a simple inheritanc ehierarchy.
6: * This class has both public and private methods.
7: * Student extends this class.
8: *
9: * @author Mark Young (A00000000)
10: */
11: public class Person {
13: /** Every Person has a name */
14: private String name;
16: /** Person requires a name */
17: public Person(String n) {
18: this.name = n;
19: }
21: /** return this Person's name */
22: public String getName() {
23: return this.name;
24: }
26: /** Change this Person's name */
27: public void setName(String nn) {
28: this.name = nn;
29: }
31: /** A method for children classes to inherit */
32: public void publicPersonMethod() {
33: System.out.println("\tin publicPersonMethod for " + this.name);
34: }
36: /** A method for children classes to inherit */
37: public void callingPrivatePersonMethod() {
38: System.out.println("\tin callingPrivatePersonMethod for " + this.name);
39: privatePersonMethod();
40: System.out.println("\tcallingPrivatePersonMethod done");
41: }
43: /** A method children classes can't call *directly* */
44: private void privatePersonMethod() {
45: System.out.println("\t\tin privatePersonMethod for " + this.name);
46: }
48: /** A method for children classes to replace entirely. */
49: public void replacedMethod() {
50: System.out.println("\tin replacedMethod for Person " + this.name);
51: }
53: /** A method for children classes to add to. */
54: public void revisedMethod() {
55: System.out.println("\tin revisedMethod for Person " + this.name);
56: }
58: /** A method to represent this Person using a String */
59: @Override
60: public String toString() {
61: return name;
62: }
64: }