Computers and Technology

Question

Based on the data definition classes identified below, assume you wish to create a Dictionary class that inherits from the Book class. In addition to title and cost, the Dictionary class must also store the number of words present in the dictionary. Write the code that will create a constructor in the dictionary class that passes in and sets the dictionary's title, cost, and number of words.

1 Answer

  • Answer:

    Explanation:

    The following code is written in Java and creates the constructor for the Dictionary class as requested. This class extends the Book class and assumes that the variables for the title and the cost are part of the Book class, so it simply calls and initializes them using the constructor.

    class Dictionary extends Book {

       int numberWords;

       

       public void Dictionary(String title, int cost, int numberWords) {

           this.title = title;

           this.cost = cost;

           this.numberWords = numberWords;

       }

    }

NEWS TODAY

You May Be Interested