+ 4
Can i access to private class var's? Ex. public class me{ private Int a = 1; private Int b = 20; } then we have the constructor and gets and setters, but in other class can I get the values of a and b? calling class or never because its private? How?
Java
4 Respuestas
0
thanks, but I can access because of the public class or because gets and setters are always public?
And by doing
public class you{
me.geta()
}
like do I need to insert class before call it? the are different classes in same package..
0
you need an instance of the class me, and acces the var's trought them.
me obj = new me();
Sytem.out.println(obj.geta());
0
Yes you can use getters and setters to access and set their values out of the class
- 3
you can acess values of a and b by getters and setters coz they're always public