×

Loading...

Jabber's comments

The answer will be 15.

This quiz tests our understanding of accessibilities for Java instance variables.

"x" is private so we cannot directly access it
by saying a.x in another class, where a is
an instance name. In the example code,
teh author used ref.x, but this piece of code is still in the definition of AClass. So the author DID NOT violate the accessibility of private variables. Hence, there won't be compiling-time error, let alone the run-time problem.

In summary, private means one cannot access a variable from out of the class definition. Say again, in the example code,
the auther used "a.x" syntax in the definition of the class AClass.

Hope it helps
Sign in and Reply Report

Replies, comments and Discussions: