This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes interface again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "interface again" Watch "interface again" New topic

interface again

payal sharma
Ranch Hand

Joined: Oct 04, 2000
Posts: 57
interface One
public void someMethod();
public class One_impl implements One
public static void main(String a[]){
public native void someMethod();
the interface above is implemented but still leaving someMethod without code and also not making this class as abstract why?
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Payal,
The keyword native is the reason why. When you use the native keyword you are telling the compiler that the implementation is external to java. The compiler only requires the class to be made abstract if it doesn't implement (or imply implementation) the interface method(s).
tvs sundaram
Ranch Hand

Joined: Jan 28, 2001
Posts: 153
Does it mean that the class One_impl need not be declared abstract? I tend to think yes based on above answer but please confirm.
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi all:
When you declare the method as native, you give the control to the OS to implement the code for that method.You will not get any compile time errors because the compiler assumes that the method is implemented in the OS dependent way.
The Developer may later on use JNI (Java Native Inteface) to implement this method.
Hope this helps,
SCJP2, OCSD(Oracle JDeveloper) OCED(Oracle Internet Platform)
I agree. Here's the link:
subject: interface again
It's not a secret anymore!