| Author |
can we achieve data hiding withe the help of encapsulation...
|
rahul S Sharma
Greenhorn
Joined: Jun 08, 2011
Posts: 21
|
|
Hi All,
Can we say that we can achieve data hiding with the help of encapsulation...?? please correct me if I am wrong....
regards....
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
|
yes, you can hide your own implementation from world.
|
 |
rahul S Sharma
Greenhorn
Joined: Jun 08, 2011
Posts: 21
|
|
But i have read at so many places that encapsulation and information hiding are two different things. According to my understanding,
encapsulation is the mechanism that binds together code an data it manipulates.
Information hiding is hiding the data by using access specifiers like private, protected or default, so how can we relate encapsulation and information hiding.
I am very much confuse in these concepts. Please help me to make clear understanding of these concepts.
thanks in advance
|
 |
chen logos
Greenhorn
Joined: Jun 16, 2011
Posts: 1
|
|
public :any class in any package can access;
private nly members in the same class can access directly;
protected: subclass or class in the same package can access directly.
|
 |
rahul S Sharma
Greenhorn
Joined: Jun 08, 2011
Posts: 21
|
|
Mr. Chen,
Welcome to ranch, i appreciate your words that you have written but i don't think this is the answer of my question...
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3065
|
|
|
Encapsulation and data hiding in Java are the same thing.
|
 |
rahul S Sharma
Greenhorn
Joined: Jun 08, 2011
Posts: 21
|
|
Mr. Stephan,
Could you please tell me how?
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3065
|
|
|
What do you mean how? They are two different terms that refer to the same thing: Restricting the visibility of members so that they are only used by the classes responsible for them.
|
 |
 |
|
|
subject: can we achieve data hiding withe the help of encapsulation...
|
|
|