Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt on uCertify question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt on uCertify question" Watch "doubt on uCertify question" New topic

doubt on uCertify question

zhong chen

Joined: Oct 12, 2009
Posts: 24

Question is: Which of the following statements is true:
A: Encapsulation breaks due to both int i and string name.
B: Encapsulation breaks due to int i.
C: Encapsulation breaks due to string name.
D: Encapsulation breaks due to int j
E: The class is fully Encapsulated.

The answer is A.
I think protected instance variable should be considered as proper encapsulation so the answer should be C. Am I right?
Deepak Bala

Joined: Feb 24, 2006
Posts: 6661

A class that extends this class should be able to access the internal variable. You can consider that as an information leak from this class, which should justify the answer

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Atwal Usha
Ranch Hand

Joined: Sep 10, 2009
Posts: 137
Encapsulation is broken if by any means the internal data of a class could be directly modified. Protected access modifier could also be considered as a cause of it.

Java Certification Exam Mock Tests: SCJA  SCJP 5  SCJP 6  SCJP 6 (Online Training)  SCJP 6 (Instructor Led Training)   SCWCD 5   SCBCD 5  SCEA 5
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: doubt on uCertify question
Similar Threads
Inheritance Question
base casting
Danchisholms: GC question, answer mismatch
Q on Kathy's Mock Test (Topic:encapsulation)
Dan's q1 on constructor from single topic