+ 1
What dose it mean to declare a vaiable private?
Tutor
3 Answers
+ 5
That way, you prevent other people who extend your code in the future to make potentially invalid changes to your variable by manipulating the variable directly.
+ 3
It means that a class that extends the class with the private variable cannot use the private var.
+ 3
Example:
class A{
private int x=5;
public int y=6;
}
public class Program extends A
{
public static void main(String[] args) {
A a=new A();
System.out.print(a.x);
}
}
//Error .
You cannot access x as it is private