Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Imagine that you have a set of related classes that have been defined using inheritance. Here are the key facts about these classes: Class Gee

Imagine that you have a set of related classes that have been defined using inheritance. Here are the key facts about these classes:

  • Class Gee doesnt explicitly extend a class (i.e., it doesnt have an extends clause in its class header). Its class members (i.e., its fields and methods) include:

    • an integer field called c
    • a string field called d
    • a non-static method called how() that takes no inputs and returns a string
    • a non-static method called where() that takes a string and returns an integer
    • its own toString() method that overrides the inherited one.
  • Class Zee extends Gee. In addition to the members that it inherits, it has:

    • a string field called a
    • its own method called how() that overrides the inherited one
    • its own method called why() that takes two integers and returns a double
    • its own equals() method that overrides the inherited one.
  • Class Tee extends Zee. In addition to the members that it inherits, it has:

    • a string field called x
    • its own method called why() that overrides the inherited one.
    • its own toString() method that overrides the inherited one.
  • Class Yee extends Gee. In addition to the members that it inherits, it has:

    • integer fields called e and f
    • its own method called where() that overrides the inherited one
    • its own equals() method that overrides the inherited one.

In addition, you should make the following assumptions:

  • All of the classes employ appropriate encapsulation.

  • Each class has a constructor that takes no parameters and initializes the newly created objects fields with their default values.

  • Each class includes an appropriate accessor method for each field that is declared in that class. For example, the Gee class would have accessor methods called getC() and getD().

  • Each class includes an appropriate mutator method for each field that is declared in that class. For example, the Gee class would have mutator methods called setC() and setD().

  1. (3 points) Now imagine that you want to add a non-static method to the Yee class. It should be called total(), it should take no parameters, and it should return the sum of all of the integer fields in the called Yee object. Add a full definition of that method to section 3-4 of your ps3_partI file. Make sure to take into account the fact that the classes employ proper encapsulation.

  2. (6 points) For each of the following assignment statements, indicate whether it would be allowed according to the rules of polymorphism, and explain briefly why or why not.

    1. Gee g = new Tee();

    2. Tee t = new Zee();

    3. Zee z = new Yee();

    4. Object o = new Zee();

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago