Wednesday 20 February 2013

12. What will be the result of executing the following code?

12.  What will be the result of executing the following code?


Choices:
a.Compilation error at line 5
b. Compilation error at line 9
c. Runtime exception at line 11
d. None of these


Answer:-
D is correct.
When no access modifier is specified for a member, it is only accessible by another class in the package where its class is defined.
Even if its class is visible in another package, the member is not accessible there.
In the question above the variable superclassVarX has no access modifier specified and hence it cannot be accessed in the packageY even though the class SuperclassX is visible and the protected method superclassMethodX() can be accessed.
Thus the compiler will raise an error at line 11.

No comments:

Post a Comment