public class Child5 extends Parent2
1: /*
2: * Part of a series of Child classes.
3: *
4: * Child5 has all Parent methods
5: * also has own method sayValue
6: * and its own instance variable
7: * also has its own constructor
8: * which uses Parent's constructor
9: * before setting its own fields
10: *
11: * @author Mark Young (A00000000)
12: */
13: public class Child5 extends Parent2 {
14:
15: // my own private field
16: private int num;
18: /**
19: * Create this child with value and number.
20: *
21: * @param reqValue the requested value (in Parent)
22: * @param reqNum the requested number (in this class)
23: */
24: public Child5(String reqValue, int reqNum) {
25: // create my Parent2 part using the String value I was given
26: super(reqValue);
28: // initialize own fields down here
29: num = reqNum;
30: }
32: /**
33: * Report this child's value.
34: */
35: public void sayValue() {
36: // I have a getValue method! I inherited it.
37: System.out.println("My value is " + this.getValue());
38: }
40: /**
41: * Return this child's number
42: *
43: * @return this Child's number
44: */
45: public int getNum() {
46: return num;
47: }
49: /**
50: * Change this Child's number
51: *
52: * @param newNum the new number for this child
53: */
54: public void setNum(int newNum) {
55: num = newNum;
56: }
58: }