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 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
Get step-by-step solutions from verified subject matter experts
