| Author |
strictfp and abstract
|
K Anshul
Ranch Hand
Joined: May 19, 2004
Posts: 71
|
|
A class be marked both strictfp and abstract. A method cannot be marked both strictfp and abstract. please tell me the reason behind this.
|
 |
Chris Allen
Ranch Hand
Joined: Feb 01, 2003
Posts: 127
|
|
|
Strictfp indicates that intermediate floating point calculations are not to be rounded so that decimal precision is not lost on the final calculation. In the case of a method which is abstract, it does not make sense to tell the compiler to use strictfp when there is no code to do the calculations with. Hence, it is not allowed. In the case of an abstract class, not all methods need to be abstract for the class to be abstract. Thus, you could potentially have some methods which are fully defined and you want the calculations to be precise.
|
 |
Angela Gordon
Greenhorn
Joined: Nov 21, 2003
Posts: 9
|
|
I have heard that abstract methods can not be marked strictfp however I tried it and I was able to compile just fine. Any ideas? I compiled the following code with 1.4: public abstract class test { public strictfp abstract void doSomething (); } Thanks, Angela
|
 |
Dan Chisholm
Ranch Hand
Joined: Jul 02, 2002
Posts: 1865
|
|
The good news is that the strictfp modifier does not appear on the exam. My mock exams once contained questions about the strictfp modifier, but I removed those questions to save Kathy and Bert the trouble of telling my mock exam users not to worry about it. Some platforms are able to do floating point calculations with a level of precision that exceeds that which is required by the Java Language Specification and by the IEEE 754 standard. Precision that exceeds the Java Language Specification can be good, but it can also contradict the "write once, run anywhere" philosophy. In situations where you want to make sure that a floating point calculation produces the same result on any platform, you can use the strictfp modifier. The strictfp modifier specifies an implementation detail that an overriding method is not required to support. For that reason, an application of the strictfp modifier to an abstract method declaration has no impact on the implementation of the overriding method in the subclass. Since the strictfp modifier is useless when applied to an abstract method, the Java Language Specification requires the compiler to throw a compile-time exception to let the programmer know that the modifier has no impact.
|
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
|
 |
Angela Gordon
Greenhorn
Joined: Nov 21, 2003
Posts: 9
|
|
Thank you Dan and also thank you for your mock exam site. I have went through all of your Study Guide 2 questions and they were very helpful!! Thanks again - Angela
|
 |
Dan Chisholm
Ranch Hand
Joined: Jul 02, 2002
Posts: 1865
|
|
Thank you for using my exams, Angela!
|
 |
 |
|
|
subject: strictfp and abstract
|
|
|