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

  Prepare a contact form and validate the data in java

Prepare a contact form and validate the data in JAVA - Validation should confirm that all input meets the requirements

  Read from a file called partyresponses

Your program will read from a file called partyResponses.txt and count the number of people who have accepted and declined the Halloween party invitation

  Wa program that takes 10 values represent

Using a loop, write a program that takes 10 values represent in exam grades (between 0 and 100) from the keyboard and outputs the minimum value, maximum value, and average value of all the values entered.

  Compute the total annual compensation of a salesperson

Create a Java application using NetBeans Integrated Development Environment (IDE) that Computes the total annual compensation of a salesperson.

  What is jit compiler

What is difference between JDK,JRE and JVM? 2. How many types of memory areas are allocated by JVM - What is JIT compiler?

  A class is a blueprint for an object

A class is a blueprint for an object. A class may have a default constructor, a constructor with arguments, accessor methods, mutator methods, public fields, and private fields.

  What is the relationship between an exception and signaling

What is the relationship between an exception, signaling and an exception handler

  An array of items that would be used by a small business

Select a task that a program could perform over an array of items that would be used by a small business.

  Write some java code that output-first half of the alphabet

Assume that next Word is a String variable that has been given a String value consisting entirely of letters. Write some Java code that outputs the message.

  supply a student tester class that tests all methods

Implement a class Student. For the purpose of this exercise, a student has a name and a total quiz score. Supply an appropriate constructor and methods getName( ), addQuiz(int score), getTotalScore( ), and getAverageScore ( ).

  Create an array of n random instances

Write a method that will create an array of N random instances of this class, where N is an integer parameter to this method and provide a toString method that will format an instance of this class nicely

  Constructs a lock with a given combination.

A combination lock has a dial with 26 positions labeled A..Z. The dial needs to be set three times. If it is set to the correct combination, the lock can be opened.

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