Jabber's comments

jabber (jabber)
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

2000-10-10 -04:00

回到话题: Java Quiz

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论