+ 1

What dose it mean to declare a vaiable private?

Tutor

13th Aug 2019, 12:19 AM
DjCisse Samuel Tsok
DjCisse Samuel Tsok - avatar
3 Antworten
+ 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.
13th Aug 2019, 3:07 AM
Sonic
Sonic - avatar
+ 3
It means that a class that extends the class with the private variable cannot use the private var.
13th Aug 2019, 1:02 AM
Ole113
Ole113 - avatar
+ 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
13th Aug 2019, 8:25 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar