+ 5
What if I create a private variable inside the main class, would that mean it'll be available in other classes? What do private variables even do?
3 Respuestas
+ 6
Private variables are only accessible from the same class/object and not by other classes.
+ 1
The private access modifier is accessible only within class.
Simple example of private access modifier
let'say we have created two classes A and Simple. A class contains private data member and private method. We are accessing these private members from outside the class, so there is compile time error.
Note : we use private only with class members i.e. with instance variables and instance methods and not with main outer class. This is one of the Java beans convention followed by developers
0
new answer