Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

possible ambiguous question(encapsulation effects polymorphism ) in whizlab ocajp 7 mock

 
Mike Mitchel
Greenhorn
Posts: 12
Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from whizlab ocajp 7 mock

Given:


Which is true?
Select one:
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 ?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Mitchel
Greenhorn
Posts: 12
Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Roel . That makes sense. Excellent explanation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic