Choice of Methods

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

Answer:

The revised class is seen below.

Choice of Methods

Now objects of the YouthBirthday class have two methods: greeting(), and greeting( String ).

// Revised version
//
class YouthBirthday  extends Birthday

{
  public  YouthBirthday ( String r, int years )
  {
    super ( r, years )
  }

  // additional method---does not override parent's method
  public void greeting( String  sender )
  {
    super.greeting();
    System.out.println("How you have grown!!/n");
    System.out.println("Love, " + sender +"/n" );
  }
}

Here is a YouthBirthday object using each of its two methods:

YouthBirthday yBday = new YouthBirthday( "Henry", 12 );
yBday.greeting();
yBday.greeting( "Alice" );

QUESTION 12:

What will this program fragment write out?