+ 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

6th Jul 2016, 12:54 PM
João Lourenço
4 ответов
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..
6th Jul 2016, 1:10 PM
João Lourenço
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());
21st Jul 2016, 9:07 PM
Hugo Agraz Diaz
Hugo Agraz Diaz - avatar
0
Yes you can use getters and setters to access and set their values out of the class
21st Aug 2016, 7:52 PM
sana shah
sana shah - avatar
- 3
you can acess values of a and b by getters and setters coz they're always public
6th Jul 2016, 1:07 PM
YOGESH SHARMA (yogi)
YOGESH SHARMA (yogi) - avatar