File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Non access modifier strictfp and intefaces 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 "Non access modifier strictfp and intefaces" Watch "Non access modifier strictfp and intefaces" New topic
Author

Non access modifier strictfp and intefaces

Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
The non-access modifier strictfp can be applied to abstract class. This makes sense because a abstract class can have non-abstract methods and when applied stricfp will be applied to all the non-abstract methods. So any floating point computation in those non-abstract methods will follow strictfp rules.
My question
a) Does strictfp gets applied to abstract methods in a abstract class?
b) Once when a concrete class extends this abstract class and implement the abstract methods, will strictfp be propograted to these methods?
c) We know that strictfp cannot be applied to a abstract method For ex
abstract strictfp void test(); is illegal. Then how come strictfp can be applied to an interfact? For example
strictfp abstract interface TestInter {} is legal. Yeah abstract keyword is optional here.
d) The question in b, Will this apply to the class implementing strictfp method.

Thanks
Deepak


SCJP, SCWCD, SCBCD
Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
Hi Deepak,

Syntax-wise, the most important thing you need to understand regarding strictfp is this: the strictfp modifier applies only to the single immediate class or method implementation that it appears with. It is not part of a method's signature, and so it is not automatically propagated to an overriding method. A strictfp method can override a non-strictfp method, and vice versa. (Note that the same freedom applies to synchronized methods.) That's why it doesn't make sense to use the strictfp modifier (or, for that matter, synchronized) for abstract methods.

On to your questions:
a) Does strictfp gets applied to abstract methods in a abstract class?

No. strictfp is intended to modify the behavior of a single specific implementation, so it doesn't make sense to talk about a strictfp abstract method.

b) Once when a concrete class extends this abstract class and implement the abstract methods, will strictfp be propograted to these methods?

Nope.

c) We know that strictfp cannot be applied to a abstract method For ex
abstract strictfp void test(); is illegal. Then how come strictfp can be applied to an interfact? For example
strictfp abstract interface TestInter {} is legal. Yeah abstract keyword is optional here.

You may be surprised to learn this dark secret of Java: interfaces are allowed to contain nested classes. Therefore, when you apply the strictfp modifier to an interface, this means that you want all of its nested classes to be strictfp.

However, there is rarely--if ever at all--a good reason to design an interface containing a nested class, especially now that Java has enums. So please try to somehow forget that you ever knew about this language 'feature'.

d) The question in b, Will this apply to the class implementing strictfp method.

Nope. An overriding method (or its class) must explicitly specify that it is strictfp, even if the method it overrides is strictfp.
[ November 23, 2007: Message edited by: Kelvin Lim ]

SCJP 5.0
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
Hi Kelvin,
I had surprised myself yesterday when i was trying combination of interface and classes. I knew that interface could be nested inside a class but i was surprised to see the other way was also true.
Infact i wanted to ask why would anybody want to nest a class inside a interface but then there was a power failure here and i got disconnected from the world
Thanks
Deepak
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Non access modifier strictfp and intefaces