+ 1

The equals method() quiz has an error

there is a private access variable x in class A, however in the question, we have class A { private int x; } A a = new A(); a.x =5; //what ?! there will be try to access private property error

24th Aug 2016, 11:13 AM
Mykhailo
4 Respostas
+ 3
I have looked thorough the class definition more deeply and noticed that it must be OK, cause the instances of type A, are created in the public static main method of same class A, so it could be valid: class A { private int x; public static void main(String[] arts) { A a = new A(); a.x = 5; } } but anyway this detail was not clarified yet, until the lesson where it appears...
24th Aug 2016, 11:55 AM
Mykhailo
0
yes, you are right
24th Aug 2016, 12:00 PM
Tiger
Tiger - avatar
0
private variables are access with in class only... and not allowed to access from outside of the class..
28th Oct 2016, 7:36 AM
Prashantha M.P
Prashantha M.P - avatar
0
Basicaly here the variable x is private and accesed from within the main method of same class so x is not out of the scope.
26th Dec 2016, 7:36 AM
Ashutosh Kumar
Ashutosh Kumar - avatar