Not Everything in an abstract Class is abstract

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:

Yes — by using an abstract class a programmer can make all children of that class look alike in important ways.

Not Everything in an abstract Class is abstract

Not everything defined in an abstract classes needs to be abstract. The variable recipient is defined in Card and inherited in the usual way. However, if a class contains even one abstract method, then the class itself has to be declared to be abstract. Here is a program to test the two classes.

abstract class Card
{
  String recipient;
  public abstract void greeting();
}

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");
  }
}

public class CardTester
{
  public static void main ( String[] args )
  {
    Holiday hol = new Holiday("Santa");
    hol.greeting();
  }
}

This is a complete, runable program. The urge to copy it to a text editor and run it must be irresistable. Remember to call the file "CardTester.java" .

QUESTION 6:

Could you write this program without using an abstract class?