• Post Reply Bookmark Topic Watch Topic
  • New Topic

regaring threads  RSS feed

 
rajareddy annavaarm
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the different between object lock and Class lock?

can a synchronize method can be overloaded?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like homework and we generally don't do others' homework. But these are very simple questions and this morning I am feeling generous...

The class lock is the lock on the java.lang.Class object associated with "this" object. Hence the lock is shared between all objects of the class.

A synchronized method can be overloaded (unless declared "final", of course), but beware because the "synchronized" keyword is not inherited.
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Errr is it just me or have you got your overridden and overloaded confused ...

A synchronized method can be overloaded (unless declared "final", of course), but beware because the "synchronized" keyword is not inherited.


Surely 'final' applies to overridden not overloaded i.e. you can declare a final method and overload it just can't override it.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, well spotted. I was answering a question about overriding, when the question asked was in fact about overloading. But then I used the wrong word, too.

I am going to guess that the original poster actually meant overriding, because the question makes no sense for overloading.

If the question really was about overloading, then the answer is that "synchronized" has no effect at all upon what overloading you can do.
[ August 06, 2007: Message edited by: Peter Chase ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!