Holiday

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:

Not surprising. You must have got it from your abstract parents.

Holiday

This stuff takes thought and practice. It took years for computer scientists to agree on this idea, and they have not stopped arguing about it.

Abstract classes are used to organize the "concept" of something that has several different versions in the children. The abstract class can include abstract methods and non-abstract methods.

Here is a class definition for class Holiday. It is a non-abstract child of an abstract parent:

class Holiday extends Card
{
  public Holiday( String r )
  {
    recipient = r;
  }

  public void greeting()
  {
    System.out.println("Dear " + recipient + ",/n");
    System.out.println("Season's Greetings!/n/n");
  }
}

The class Holiday is not an abstract class. Objects can be instantiated from it. Its constructor implicitly calls the no-argument constructor in its parent, Card, which calls the constructor in Object. So even though it has an abstract parent, Holiday objects are as much objects as any other.

  • Holiday inherites the abstract method greeting() from its parent.
  • Holiday must define a greeting() method that includes a method body (statements between braces).
  • The definition of greeting() must match the signature given in the parent.
  • If Holiday did not define greeting(), then Holiday would be declared an abstract class.
    • This would make it an abstract child of an abstract parent.

QUESTION 5:

Will each of the classes that inherit from Card have a greeting() method?