Question: 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

 In determining whether a class B should be a subclass of

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. Won't 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!