Java Programming - Declarations and Access Control - Discussion

15. 

Which of the following class level (nonlocal) variable declarations will not compile?

[A]. protected int a;
[B]. transient int b = 3;
[C]. private synchronized int e;
[D]. volatile int d;

Answer: Option C

Explanation:

Option C will not compile; the synchronized modifier applies only to methods.

Option A and B will compile because protected and transient are legal variable modifiers. Option D will compile because volatile is a proper variable modifier.


Tintu said: (Jul 20, 2014)  
Synchronized modifier not only applied for method. It also applied for blocks.

Guruputra said: (Mar 31, 2015)  
How the transient can became access-specifier?

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.