/* Author: James Tam Version: October 19, 2015 Learning: * Using the super keyword to access the super class constructor * Using the super keyword in toString() to implement some behavior in the parent (returns String representation of the parent attributes and some behavior in the child). Builds on String created by the parent and adds the attributes of the child. */ public class Hero extends Person { private int heroicCount; public Hero() { super(); heroicCount = 0; } public Hero(int anAge) { super(anAge); heroicCount = 0; } public void doPersonStuff() { System.out.println("Pffff I need not go about mundane" + " nicities such as eating!"); timeDelay(); super.doPersonStuff(); timeDelay(); System.out.println("...well actually I do :$"); } public void doHeroStuff() { System.out.println("Saving the world for: truth!," + " justice!, and all that good stuff!"); heroicCount++; } // A 'helper method' that is to be used internally (by other) // class methods so it's functionality is hidden (private). private void timeDelay() { final long DELAY_TIME = 1999999999; for (long i = 0; i <= DELAY_TIME; i++); } // Returns string representation // 1) Makes a request of the parent method to return a String // representation of parent class attributes // 2) Adds to this string by concatenating a String // representation of the child attributes. // 3) The total String is then returned to the caller. public String toString() { String s = super.toString(); if (s != null) s = s + "\n" + "Count of noble and heroic deeds " + heroicCount; return(s); } }