Source of TestChildren2.java


  1: import java.util.Scanner;
  2: import csci2341.Utilities;

  4: /*
  5:  * A program to demonstrate inheritance using Parent and Child classes.
  6:  *
  7:  * @author Mark Young (A00000000)
  8:  */
  9: public class TestChildren2 {

 11:     public static void main(String[] args) {

 13:         // introduce yourself
 14:         System.out.println("This program is a variation on TestChildren.");
 15:         System.out.println("In this program the parent class is Parent2, "
 16:                 + "and it sets its value in the constructor.");
 17:         Utilities.pause();

 19:         // Parent with constructor
 20:         Parent2 p = new Parent2("Frank");
 21:         System.out.println("Parent's value is: " + p.getValue());
 22:         Utilities.pause();

 24:         // about calling a parental constructor
 25:         System.out.println("All of the child class objects in this program "
 26:                 + "call super(_) in their constructor,\n"
 27:                 + "to initialize their value.");
 28:         Utilities.pause();

 30:         // Child with constructor
 31:         Child4 c4 = new Child4("Fred");
 32:         c4.sayValue();
 33:         Utilities.pause();

 35:         // Child with extra field
 36:         Child5 c5 = new Child5("Harold", 21);
 37:         c5.sayValue();
 38:         Utilities.pause();
 39:     }

 41: }