This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Which of the following statements are true? a) Encapsulation and Information hiding are used interchangeably. b) Encapsulation is a language feature. c) Information hiding is a design principle. d) Java can have encapsulated data that is not hidden. e) All of the above
I was attempting this question and trying to understand : - 1. the difference between encapsulation and data/information hiding? 2. How Encapsulation is a language feature. examples? 3. How Information hiding is a design principle. examples?
as per answer d) it seems to me that when you have public getter and setter for public instance variable - its encapsulation. but when you make your instance variable as private. its data hiding. is my understanding correct? Please help
- Information Hidding is a private attribute, so you cant access directly. - Encapsulation is a public getter and setter for a attribute private/protected/default/public. - So, encapsulation can be for any access modifier, but the correct encapsulation is given by methods get/set for a private attribute.
The concept of "encapsulation" refers to shielding data and the details of methods from client objects. It is not a language feature, it is a object-oriented software design principle. B is false. Whether it is easily implemented or difficult to implement with a particular language is another concept.
The term "information hiding" might be used by non-programmers, or programmers that don't fully understand encapsulation. A is border-line false. Information hiding is not an object-oriented term and can be used in regards to non-object-oriented languages and even in business contexts.
Java is a programming language and cannot have encapsulated data. A Java-based class may encapsulate data. What the term "hidden" means is undefined. To call something "encapsulated" means that client objects do not have access to it and this can translate to it being "hidden". So, D is false.
The only true statement would be C. [ July 08, 2008: Message edited by: James Clark ]
a) Encapsulation and Information hiding are used interchangeably.
Yes, yes they are. And people use JDK and JRE interchangeably. But the JDK and the JRE are two different things. But people use those terms interchangeably. It doesn't mean they are the same thing. I think this is a very poor statement.
b) Encapsulation is a language feature.
A language feature? Not sure exactly what a language feature is? Are keywords language features? Is it a language feature if a programmer doesn't have to do anything, ie, the system does it automatically?
If I declare a variable, it is not automatically encapsulated. The Java language does not do anything to automatically encapsulate the data. I don't know what a "language feature" is, and I don't think you'll ever hear this term being used on the SCJA exam.
c) Information hiding is a design principle.
A design principle?
prin�ci�ple - a fundamental doctrine or tenet; a distinctive ruling opinion - dictionary.com
Well, you should make your data private and accessible through public setters and getters. I guess that is a commonly accepted philosophy, so I think this is correct.
d) Java can have encapsulated data that is not hidden.
If a variable is private, but accessible through public setters and getters, it is philosophically encapsulated, but it is not actually hidden, so this is true.
e) All of the above
I always think "All of the Above" options are bogus.
That's my take. I think it has the air of someone stretching to make an exam question, and as such, the wording is poor and misguiding.
Joined: Apr 01, 2008
Thanks Raphael , James and Cameron for help. And I would say that wordings are poor. Encapsulation is not a language feature as well as information hiding is not a object oriented term. It seems that term 'data or information' hiding is used to explain or support Encapsulation. I think D is correct as we can encapsulate data but if we do not mark it as private we can access it even without using access methods. the term 'hidden' seems to explain this behavior.
I would like suggest reading Head First Java for this. They have also explained it very well.