How we can achieve Encapsulation in Java? (using any keywords or methods etc)
NOTE : [This question was asked by Srivani]
How we can achieve Encapsulation in Java? (using any keywords or methods etc)
NOTE : [This question was asked by Srivani]
Simple. Use a class. (just like C++). Use specifiers like private and public to distinguish beween data to be hidden and revealed.
(Correct me if I am wrong. I am a novice in Java)
Cheers!
Kalayama
[COLOR="Blue"][SIZE="2"]"If you are not living on the edge of your life, you are wasting space"[/SIZE][/COLOR]
Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"
Hi
take a class and define members (i.e variables and methods). class encapsulate members by controlling the access of the members. this controlling is handled by access specifiers.
Define a class with all the data members declared as private so that they are not publically accessible to any other class and all the methods that works upon or uses these data members as public. In this way encapsulation is achieved in Java.