synchronized class aClassname { in which situation?

What we say '"synchronized" can be placed in either method or object,

I heard better use on method than object.

Why?

I've seen the code that was with method

synchronized deposit() {}

synchronized withdraw() { }

but not with object.

what would be in real-life implementation for putting

synchronized class aClassname {

}

I cannot think of it. what would be

[426 byte] By [PaulSheldonII_Screena] at [2007-10-3 7:33:19]
# 1

> synchronized class aClassname {

You can't do that. The syntax of the synchronized statement is:

synchronized ( Expression ) Block

The type of Expression must be a reference type. As a convenience, a method may be declared synchronized; such a method behaves as if its body were contained in a synchronized statement. The locks acquired by synchronized statements are the same as the locks that are acquired implicitly by synchronized methods. If the method is an instance method, it locks the lock associated with the instance for which it was invoked. If the method is static, it locks the lock associated with the Class object that represents the class in which the method is defined.

http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#255769

http://java.sun.com/docs/books/jls/second_edition/html/memory.doc.html#30206

YoGeea at 2007-7-15 2:33:13 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
Then what can you answer the question below: Is it synchorized based on method or object?Message was edited by: PaulSheldonII_Screen
PaulSheldonII_Screena at 2007-7-15 2:33:13 > top of Java-index,Java HotSpot Virtual Machine,Specifications...