| Author |
Abstract Synchronized
|
James Tharakan
Ranch Hand
Joined: Aug 29, 2008
Posts: 580
|
|
|
Why we cannot declare a method as abstract and synchronized?
|
SCJP 6
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.
(peace)
|
Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
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
Bartender
Joined: Aug 16, 2005
Posts: 12909
|
|
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 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: Abstract Synchronized
|
|
|