public class Child3 extends Parent
1: /**
2: * Part of a series of Child classes.
3: * Simple example of inheritance
4: * Child3 has its own method
5: * sayValue
6: * also has all Parent methods
7: * but has replaced the Parent's getValue method
8: * with a version that uses the Parent's getValue method
9: *
10: * @author Mark Young (A00000000)
11: */
12: public class Child3 extends Parent {
14: /**
15: * Report this child's value.
16: */
17: public void sayValue() {
18: // this method uses my own (specialized) getValue method
19: System.out.println("My value is " + this.getValue());
20: }
22: /**
23: * Get my own value. Overrides getValue in Parent -- but uses that method
24: * as a basis for the new value it returns.
25: *
26: * @return a twee interpretation of my value
27: */
28: public String getValue() {
29: // my real value is what my Parent says it is
30: String myRealValue = super.getValue();
32: // but I'm a Child, so I'm a bit twee....
33: String howISayIt = myRealValue.replace('r', 'w');
35: return howISayIt;
36: }
38: }