Which is true?
A. The class is fully encapsulated.
B. The code demonstrates polymorphism.
C. The owner variable breaks encapsulation & would eventually affect polymorphism.
D. The simId and talkTime variables break polymorphism.
E. The setSimInfo method breaks encapsulation. Incorrect
The answer is C
But I couldn't understand the statement
& would eventually affect polymorphism
Could somebody please explain how lack of encapsulation affects polymorphism ?
First of all let us agree that this class is not well-encapsulated. I think that's the most important observation to take from this question
Don't know what they mean with "lack of encapsulation affects polymorphism". But let me give it a shot with the following example:
For an old Nokia we want the owner to be stored in upper case. So we override the setSimInfo method. But because owner is public, it can be set without invoking setSimInfo and that would thus affect polymorphism.