wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interfaces and synchronized keyword 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 "Interfaces and synchronized keyword" Watch "Interfaces and synchronized keyword" New topic
Author

Interfaces and synchronized keyword

Paulo Aquino
Ranch Hand

Joined: Apr 29, 2002
Posts: 200


Why is it that the method1 under TwoInterfaces doesn't give a compiler error when I added to it a synchronized modifier?


Be Afraid...Be very Afraid...
Kalyani Marathe
Ranch Hand

Joined: Apr 06, 2005
Posts: 72
The classes implementing interfaces are required to have public method and then you can use any other modifier to it like synchronized or native.
Paulo Aquino
Ranch Hand

Joined: Apr 29, 2002
Posts: 200
Yeah...thanks...but you can't use native here because native must not have any body right?
Francisco Gonzalez
Greenhorn

Joined: Apr 11, 2005
Posts: 15
Actually you can try it and see

-Francisco
Francisco Gonzalez
Greenhorn

Joined: Apr 11, 2005
Posts: 15
To add some more.

when you're implementing an interface, what you're basically doing is overriding the methods defined in that interface. So all overriding rules apply, which does not restrict you from use modifiers such as: synchronized and native even abstract if it's an abstract class that implements the interface.

You need to keep the same signature, the access modifier can't be more restrictive, do not throw any new or broader checked exception, etc,etc

Regards,
Francisco.
 
GeeCON Prague 2014
 
subject: Interfaces and synchronized keyword