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

  Cross-cultural opportunities and conflicts in canada

Short Paper on Cross-cultural Opportunities and Conflicts in Canada.

  Sociology theory questions

Sociology are very fundamental in nature. Role strain and role constraint speak about the duties and responsibilities of the roles of people in society or in a group. A short theory about Darwin and Moths is also answered.

  A book review on unfaithful angels

This review will help the reader understand the social work profession through different concepts giving the glimpse of why the social work profession might have drifted away from its original purpose of serving the poor.

  Disorder paper: schizophrenia

Schizophrenia does not really have just one single cause. It is a possibility that this disorder could be inherited but not all doctors are sure.

  Individual assignment: two models handout and rubric

Individual Assignment : Two Models Handout and Rubric,    This paper will allow you to understand and evaluate two vastly different organizational models and to effectively communicate their differences.

  Developing strategic intent for toyota

The following report includes the description about the organization, its strategies, industry analysis in which it operates and its position in the industry.

  Gasoline powered passenger vehicles

In this study, we examine how gasoline price volatility and income of the consumers impacts consumer's demand for gasoline.

  An aspect of poverty in canada

Economics thesis undergrad 4th year paper to write. it should be about 22 pages in length, literature review, economic analysis and then data or cost benefit analysis.

  Ngn customer satisfaction qos indicator for 3g services

The paper aims to highlight the global trends in countries and regions where 3G has already been introduced and propose an implementation plan to the telecom operators of developing countries.

  Prepare a power point presentation

Prepare the power point presentation for the case: Santa Fe Independent School District

  Information literacy is important in this environment

Information literacy is critically important in this contemporary environment

  Associative property of multiplication

Write a definition for associative property of multiplication.

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