Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Object- Oriented Design Using JAVA questions- 1- In determining whether a class B should be a subclass of A, we said that there should be

Object- Oriented Design Using JAVA questions-

1- In determining whether a class B should be a subclass of A, we said that there should be no surprises to the client who thinks she has an object of class A when she really has an object of class B. However, suppose B is any subclass of any class A and consider the following code:

public String getClassNameOf(A a)

{

return a.getClass().getName();

}

The client will always be expecting to see A returned regardless of the argument, but if an object of class B is the value of the parameter a, then B will be returned. Wont that surprise the client? Does this mean that no class should ever be a subclass of another class because there will always be this surprise?

2-In the Sorter class defined, it was mentioned that the generic sort method will not work for arrays of primitive types. Come up with an elegant way of handling such arrays. Actually think this through, do not give a simplistic off-the-cuff answer. What problems could be associated with your method?

3-Suppose a person needs to model the concept of balloons and so, wishing to use inheritance to make an elegant design, the person creates three classes, a RubberObject class, an InflatableBag class, and a Balloon class that is a subclass of those two classes. (For the purpose of this exercise, assume that Java, like C++, allows multiple inheritance.) Can you see any problems with this design?

Please explain briefly with examples.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions