posted 18 years ago
Abhishekxp-
You are correct in that a static method can access non-static methods via an instance of a class, but generally questions about what is accessible from a static method are not asking about that. They want to know what you can access directly - without any instance of a class. And in that case, the answer is that a static method can only access static methods and variables. Through an instance class they can access non-static methods and variables, but only through the instance. That is why b is true.
As for the synchronized keyword, it only applies to methods or blocks of code. It doesn't apply to variables. In the case of a method it preceeds the return type of the method.
In the case where it's a a block, the syntax looks like this:
Where this is the current object. this could also be replaced by a different object on which you want to synchronize.
While in the strictest sense of the question the synchronized keyword does appear before a variable in the case of a synchronized block that is synchronized on a variable, the question is really asking what things it is valid for the synchronized keyword to modify. And the answer to that is that the synchronized keyword can modify a method or a block of code.
Hope that helps,
Josh
[ February 05, 2006: Message edited by: Joshua Smith ]