Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialsagar sen
119 Pointswhy i cant add private as in TextView and Button?
the private button is not possible on the Textview and Button .. it is now made into public. what shall i do to make it into private one
1 Answer
ian de Jesus
3,401 PointsThe reason why these are declared as private is to folllow the rule of Encapsulation which is one the four fundamental Object Oriented Programming concepts. And I quote
"Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as as single unit. In encapsulation the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class, therefore it is also known as data hiding.
To achieve encapsulation in Java
Declare the variables of a class as private.
Provide public setter and getter methods to modify and view the variables values." http://www.tutorialspoint.com/java/java_encapsulation.htm