Adding the Interface

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 blanks are filled in, below.

Adding the Interface

The child class Food extends the parent class. It uses super to use the parent's constructor and the parent's display method.

class Food extends Goods
{
  double calories;

  Food( String des, double pr, double cal)
  {
    super( des, pr );
    calories = cal ;
  }

  void display()
  {
    super.display( );
    System.out.println( "calories: " + calories );
  }
}

QUESTION 9:

(Review :) Would it be correct to reverse the order of the statments in the constructor for Food?