Search code examples
javaabstract-methodsstrictfp

Reasons behind why abstract and strictfp keywords cannot be used together in a method declaration?


I'm reading SCJP by katherine sierra.
I understand that abstract and final keywords cannot be used together because they contradict each other as explained in the book.

However, I don't understand why strictfp and abstract keywords cannot be used together.
I don't know how the strictfp keyword exactly works in Java yet.

In my thoughts, one could declare an abstract strictfp method, have a subclass, and implement that method in the "strictfp way".

What is the reason these keywords don't get along well together ?
EDIT
I've double checked the book and it surely says

Because interface methods are abstract, they cannot be marked final, strictfp , or native .

from SCJP by Katherine Sierra. page 21.

Also my IDE(Eclipse Juno) says I can't use abstract and strictfp keywords together.
Hmmm, why not though ?


Solution

  • Katherine Sierra was probably talking about abstract methods. It would make no sense to make an abstract method strictfp because an abstract method just provides a method signature (and throws clause if any), to use it we need to override it in a subclass with a concrete method and this method will have its own modifiers which will override its parent method's modifiers. That is, methods do not inherit modifiers.

    Note that it's not only sctriptfp, but no modifiers are allowed on abstract methods except public and protected. You'll get a compile-time error if you try.