Example Problem

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. You might wonder that it does not extend a base class, but it does. If no other class is extended, Object is the base class. SmallClass extends Object and implements InterfaceA.

Example Problem

Let us create a database program for a store. The store sells:

  • Goods, each of which has the attributes:
    • description
    • price
  • The types of goods are:
    • Food—with an attribute "calories". Food objects are not taxable.
    • Toy—with an attribute "minimumAge". Toy objects are taxable.
    • Book—with an attribute "author". Book objects are taxable.

There are many things that are taxable that are not goods, such as services or entertainment. Also, not all goods are taxable. So we want to have the concept "taxable" as a separate concept, not part of the concept of Goods. Here is what the concept Taxable looks like:

  • A Taxable item,
    • has a taxRate of 6 percent,
    • has a calculateTax() method.

When implemented in Java, these concepts will appear as classes and an interface.

QUESTION 6:

(Design question: ) Decide on an implementation for each concept:

ConceptParent Class, Child Class, or Interface?
Goods
Food
Toy
Book
Taxable