Classes that have been defined using inheritance

Assignment Help JAVA Programming
Reference no: EM131914506

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 doesn't explicitly extend a class (i.e., it doesn't have an extends clause in its class header). Its class members (i.e., its fields and methods) include:
  • integer fields x and y
  • a non-static method called foo() that takes no parameters and returns a String
  • 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 par
  • a non-static method called moo that takes an integer and returns a String
  • its own toString() method that overrides the inherited one.
  • Class Yee extends Gee. In addition to the members that it inherits, it has:
  • an integer field z
  • its own toString() method that overrides the inherited one.
  • Class Tee extends Yee. In addition to the members that it inherits, it has:
  • a String field called bar
  • an 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 object's fields.
  • 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 getX() and getY().
  • 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 setX() and setY().

Answer the following questions in light of the above information about these classes. Before you begin, you may find it helpful to draw an inheritance hierarchy for these classes, although doing so is not required.

  1. The information above states that the Gee class has its own toString() method that overrides the inherited one. Where does the toString() method that Gee overrides come from? Be as specific as possible, and explain your answer briefly.
  2. List all of the fields in a Tee object - both the ones that it declares and the ones (if any) that it inherits.
  3. Consider the following code fragment:
Tee t1 = new Tee();
System.out.println(t1.equals(t1));
System.out.println(t1.foo());
System.out.println(t1);
System.out.println(t1.moo());

Each of the print statements in this code fragment displays the result of a method call. (This includes the third print statement, in which the Java interpreter calls a method on our behalf.) However, it is possible that one or more of these methods calls would fail to compile because the necessary method is neither defined in the Tee class nor inherited from a superclass of Tee.

Copy the table below into your ps3pr2.txt file, and complete it with appropriate information about each of the method calls. We have filled in the first row for you.

              |              | will the call | if the call compiles,   
  which print | which method | compile       | which version of the    
  statement   | is called    | (yes/no)?     | method will be called?  
=======================================================================
| first one   | equals()     | yes           | the Tee version        |
+-------------+--------------+---------------+------------------------+
| second one  |              |               |                        |
+-------------+--------------+---------------+------------------------+
| third one   |              |               |                        |
+-------------+--------------+---------------+------------------------+
| fourth one  |              |               |                        |
+-------------+--------------+---------------+------------------------+

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

5. 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. Yee y = new Tee();
  2.     Zee z = new Gee();
  3.     Tee t = new Zee();
  4.     Gee g = new Tee();

Reference no: EM131914506

Questions Cloud

What are the advantages and disadvantages of bonds : Why might a company choose to raise money through bonds, rather than take out a note payable? What are the advantages and disadvantages of bonds?
Do gun manufacturers have social responsibility for products : Do you agree with Hass? Explain. Do gun manufacturers have a social responsibility for their products beyond the demands of the market and the law? Explain.
Market values of long-term debt : Current liabilities' book and market values stand at $8 million and the firm's book and market values of long-term debt are $15 million.
Discuss about the federal education policies : Select one of the following public policy issues and assess its effectiveness. What changes may be needed and why?
Classes that have been defined using inheritance : Imagine that you want to add a non-static method to the Yee class. It should be called yow(), it should take no parameters, and it should return the sum of the
What is the working average cost of capital : Consider a company financed with 0.9 equity, 0.1 preferred stock, and the remaining debt subject to a corporate tax rate 0.4
Prepare the journal entries for milani related to investment : Milani, Inc., acquired 10 percent of Seida Corporation on January 1, 2017. Prepare the 2018 journal entries for Milani related to its investment in Seida.
Exploring the barriers to e-commerce adoption : What PROBLEM STATEMENTS can be formulated for barriers to E-commerce adoption among SMEs to support a QUALITATIVE RESEARCH METHOD?
Expected rate of return of hayek corporation : What is the variance in the expected rate of return of Hayek Corporation?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd