File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Interfaces 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 "Doubt in Interfaces" Watch "Doubt in Interfaces" New topic

Doubt in Interfaces

Jehaan Butt
Ranch Hand

Joined: Feb 05, 2009
Posts: 41
Given the following code:
interface Bilbo {
// << insert code here
Which methods can be declared at the position indicated and not cause a compile-time error?

The options are:

a. public abstract void drawSting();
b. public static void drawSting();
c. void drawSting();
d. strictfp void drawSting();
e. protected void drawSting();

Answer: The correct options are A and C.
Interface method declarations are implicitly public and abstract, and these modifiers can be omitted. Interface methods cannot be static (ruling out C), nor can they be marked strictfp (ruling out A), final or native. Marking E protected conflicts with the restriction that interface methods must be public.

I have a doubt about the strictfp point. Why aren't interface methods meant to be marked strictfp? I am asking merely from a curious programmer's POV.

The question is from Java Inquisition's Tough SCJP questions test.

Kamil Wojcik
Ranch Hand

Joined: May 19, 2008
Posts: 78

Note that a method declared in an interface must not be declared strictfp or native or synchronized, or a compile-time error occurs, because those keywords describe implementation properties rather than interface properties. However, a method declared in an interface may be implemented by a method that is declared strictfp or native or synchronized in a class that implements the interface.

SCJP 6.0 Passed | SCWCD Passed | PSM in progress...
Ankit Garg

Joined: Aug 03, 2008
Posts: 9466

There is no use of marking an abstract method strictfp. If you override a method which is not strictfp, you can add the strictfp to the overriding method. Abstract methods don't have any body so won't have any floating point calculations in them, so marking them strictfp is completely useless...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
Interface are mainly used to provide abstract funtionallity and so that any user who implement the interface can have their own implementation.

User A may want his implementation use sctrictfp in his calculation where as user B does not need this.

So if you were able to put strictfp in the method declaration in the interface eventhough user B does not need sctrictfp behaviour,he is forced to do which is not the purpose of interface.

To keep it simpe no non access modifiers can be used with abstract modifiers in the method declaration.

Hope you are clear now.


Failure is not an option.
Jehaan Butt
Ranch Hand

Joined: Feb 05, 2009
Posts: 41
Yep, got it. Thanks all
I agree. Here's the link:
subject: Doubt in Interfaces
jQuery in Action, 3rd edition