wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Abstract Synchronized Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Abstract Synchronized" Watch "Abstract Synchronized" New topic

Abstract Synchronized

James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Why we cannot declare a method as abstract and synchronized?

Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
because its better not to do it since its better to synchronize your code at block levels instead of making the whole method as synchronized, however note that when you define a concrete implmentation of the method you can specify that its synchronized.


Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
Ankit Garg

Joined: Aug 03, 2008
Posts: 9462

Just to make it more clear, if you have an abstract method, then while overriding you can add the synchronized keyword to the method. And if a method is synchronized (non-abstract method of course), then while overriding it, you can remove the synchronized keyword. So there's no point in making an abstract method synchronized as the overriding code can add or remove the synchronized keyword on will. This behavior of the synchronized keyword is because synchronized is not a part of method signature...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Prav sharma
Ranch Hand

Joined: Feb 07, 2005
Posts: 102
Rightly said. SYnchronised is not a part of the method signature.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15081

Whether a method needs to be synchronized or not, depends on how that method is implemented.

Since an abstract method has no implementation at all, it doesn't make sense to make it synchronized.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link: http://aspose.com/file-tools
subject: Abstract Synchronized
It's not a secret anymore!