Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronized class  RSS feed

 
Siva Prasad
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we declare a class with synchronized specifier like this?
public synchronized MyClass
{
...
}
If so, what is the behaviour of that class when we instantiate it?
Cheers
Siva Prasad
 
Rahul Rathore
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NOPE. See JLS. A top-level class can be public and/or it can be abstract and/or it can be final. An inner class can be all of the above and it can also be private or protected and/or static. But a class whether top-level or inner can never be synchronized.
synchronized keyword is used only for qualifying a method or a block.
For a discussion on synchronized method/block see http://www.javaranch.com/ubb/Forum27/HTML/000259.html
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!