adspace
I am newbie in J2EE & looking for strong basic behind each
concept as,
Why do we use private access specifier before each variable
of
type property bcoz ultimately to access it outside the class
we use public method as getter & setter ?
If we use getter & setter to access it outside the class so
better we make variable as public so that it is easily
available outside of the class...
Please guide me why do we use as private ????
Answer Posted / Km Subhash Rani
Using private variables ensures that the data is encapsulated within the class, promoting data integrity and hiding implementation details. The getter and setter methods provide controlled access to these private variables, allowing you to perform validations or operations if needed.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers