why we can't specify like the following code
synchronized class a
{

--

}

if we want to synchronize a class we need to code like

synchronized(a.class) ?

If any body help me I will be very thankfull to them.

IMO, a class provides a template for the creation of objects. It doesn't make sense to make a class synchronized. You can always make all the methods of a class synchronized if you want or place synchronized blocks inside methods and .

Read this whole thing.

only correct answer: because the language specification doesn't allow it.
Why it doesn't allow it you should ask the people who invented the language, but better make sure you have a less silly reason for the question than "it was asked during an interview" because they'll be more likely to enter into a debate about the futility of stupid interview questions than language design decisions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.