• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Encapsulation Question

 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Question 5

A class can not be called "tightly encapsulated" unless which of the following are true?
a. The data members can not be directly manipulated by external code.
b. The class is declared final.
c. It has no public mutator methods.
d. The superclass is tightly encapsulated.


The answer is given: a,d
Description to "d", if the super class is not tightly encapsulated no subclasses can be tightly encapsulated.
Please clarify.


Source of the question



Thanks and Regards,
cmbhatt
 
Srinivasan thoyyeti
Ranch Hand
Posts: 557
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Chandra,

Come on...! Super Class can easily break option (a) given in qustion, which you have selected as a rule for tight encapsulation !.

Thats why we should select (d) too.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way to put this might be: If the superclass is weak or vulnerable, then any subclasses will inherit that weakness or vulnerability.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If the superclass is weak or vulnerable, then any subclasses will inherit that weakness or vulnerability.


I liked this!


Thanks marc!

cmbhatt
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic