Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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

 
Greenhorn
Posts: 12
Eclipse IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Roel . That makes sense. Excellent explanation.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic