Question
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().
-
(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.
-
(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.
-
Gee g = new Tee();
-
Tee t = new Zee();
-
Zee z = new Yee();
-
Object o = new Zee();
-
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started