Definition for inheritance-based polymorphism

Assignment Help Other Subject
Reference no: EM132249084

Java Polymorphism

1. Provide a definition for Inheritance-based polymorphism (as opposed to Interface-based polymorphism)

2. Provide a definition for Interface-based polymorphism (as opposed to any Inheritance-based polymorphism)

3. It is possible for methods in separate classes to exist, coincidentally bearing the same name/signature without their having been inherited from another class or interface.

a) Could these also described as "polymorphic" calls?
b) What downsides might we experience in attempting to use them polymorphically?

4. Given only the classes shown in Diagram 1 above: provide their implementations, and complete a working version of the following Java main() method of the Pgm class to correctly determine the total carrying-capacity of a fleet of vehicles. Note: assume the above diagram is complete (no other methods, properties, classes or Interfaces available), and final (no additional methods/properties may be created). You may assume any three unique, positive values x, y, z for the three Automobile-types' capacities.

public class Pgm {
public static void main(String[] args) {
int totalCapacity = 0;
Automobile[] fleet = new Automobile[]{
new Sedan("black"),
new Minivan("blue"),
new SportsCar("red")};
:
:
:
}
}

5. What does the code you had to write in #4 above suggest to you about the limitations of "coincidental" polymorphic methods not based on Inheritance/Interfaces?

Note: before coding up #6, please read all the way to the bottom of these instructions until you find the string: "You may now begin to code"

6. Consider an Automobile class with the following implementations of equals methods:
public boolean equals(Object o) {...}
// Note: override the Object-Class method -- Version A
public boolean equals(Automobile o) {...} // Version B

and a class Sedan that is a subclass of Automobile with the following methods:
public boolean equals(Automobile o) {...} // Version C
public boolean equals(Sedan o) {...} // Version D

and a class Minivan that is a subclass of Automobile with the following methods:
public boolean equals(Automobile o) {...} // Version E
public boolean equals(Minivan o) {...} // Version F

Now suppose you have the following six variables:
Object o = new Automobile();
Automobile auto = new Automobile();
Automobile sedanAuto = new Sedan();
Automobile minivanAuto = new Minivan();
Sedan sedan = new Sedan();
Minivan minivan = new Minivan();

There are 36 ways each of these variables can be paired off in a call to equals, where one of the six is being sent the equals message and one of the six is the argument to equals. For each such pair, indicate which of the equals methods will be executed. For example, if there is a call
auto.equals(auto)
then version B will be called.

List the method-call and result of all 36 calls generated by passing each of the 6 variables above (in the specified order) as arguments (i.e. parameters) to each of the 6 variables, in order. (That is, six separate method-calls to o, followed by six calls to auto, etc.) . Implement each equals() method as a: System.println("Method X") string.

Note: Out-of-order calls are liable to be marked wrong, even if correct!!!

Problem #6 instructions:
- Type out the 36 calls in the correct order as specified (partially demonstrated above)
- On the same line, include your prediction of the printed output for each of the 36 calls
- Implement a main() method that makes the 36 calls in the correct order and run your code
- For each incorrect prediction, explain to me using the 2-step description we went over in class why the Java result is actually correct!
Note: you will not be penalized for incorrect predictions -- only for missing explanations!
The Powerpoint used in-class (lect2pt2_cs3360.ppt) is now in your course INFO folder

- You may now begin to code

Attachment:- Polymorphism.rar

Verified Expert

The solution file is prepared in ms word and implemented all codes in NetBeans (java) which explained about the interface, inheritance and polymorphic method calls.Here we have considered various classes are mini van, sportscar and sedan classes derived from automobile class and overridden method gets capacity.We created an object for all classes to calculate the total capacity of fleet vehicles.

Reference no: EM132249084

Questions Cloud

Briefly explain the tool and technique or framework : Briefly explain the tool, technique or framework. Set the scene for you own professional context (e.g. use in marketing, consultancy, engineering etc.)
Anyone can explain what is effective communication : Anyone can explain what is effective communication? Please list the three main types of communication skills.
What budget procedure would allow him to do that : What budget procedure would allow him to do that?
Evaluate tesco brand product and marketing evolution : Evaluate Tesco brand's product and marketing evolution over the years. What's most important to the Tesco brand with respect to changes in how consumers shop.
Definition for inheritance-based polymorphism : CS3360 – Object-Oriented Program Development - Java Polymorphism - Provide a definition for Inheritance-based polymorphism
Describe the important marketing-related datapoints : Step Two - Compile research on the a) company, b) its customers, c) its competitors, and the d) community (its market area).
Level of output yn what happens to inflation : When Output Y is higher than the natural level of output Yn what happens to inflation?
Build a simple linear model by regressing Y on X : Build a simple linear model by regressing Y on X and testing whether or not a relationship exists between the number of drivers and the number of trucks
What is stakeholder perspective : What is Stakeholder Perspective and why is their perspective important?

Reviews

Write a Review

Other Subject Questions & Answers

  How a manager should address the human and product issues

Evaluate in 1,750 words how a manager should address the human and product issues that will arise from global expansion. Assess specifically how the organizational structure might change, how to handle change management

  How evaluations are to be carried out to measure

Tracking: - identified how evaluations are to be carried out to measure and track the project progress over time Present project/teaching at community.

  Discussing about commercial suppliers

An unpriced change order is issued. If the specific-cost-method of calculating an equitable adjustment is used, what would the contractor be compensated for?

  Describe the contemporary united states

If Nietzsche were alive today, would he describe the contemporary United States as being governed by master morality or slave morality? Explain, and be specific

  Why do you feel work plays such a vital role in the life

Why do you feel work plays such a vital role in the life of an individual, regardless of monetary compensation? Do you believe that different cultures place.

  Discuss analysis in criminal justice policy making

assesses the issues surrounding the collection and analysis in criminal justice policy making. Special attention should be given to programs

  Does the current system support the expenditures

Do the fees associated with expatriates inhibit healthcare organizations from attracting foreigners to fill staffing positions?

  What might that mean for the adult participant future health

Evaluate the impact of the family's genetic history on your adult participant's health. Health issues: obesity, diabetes, dementia, lung cancer, pulmonary hypertension. What might that mean for the adult participant's future health?

  Discuss what are the implications of using a convenience

What are the implications of using a convenience sample on the way that you interpret and use the findings

  What is the present perspective on this problem

What is the history of this particular problem? When was it first identified? How has it been viewed historically?

  Discuss adaptations of whole plant communities

Three key abiotic factors which have had a major bearing on plant adaptations in Australian biomes are: light, water and fire. Using examples from Australian native ecosystems, describe and discuss adaptations of whole plant communities

  In the song for night

In the "song for night" by Chris Abani. What was the village-life like before and after the war? In a novel of so much horror, where do we find love, grace, and beauty?

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