Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface again

 
payal sharma
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
interface One
{
public void someMethod();
}
public class One_impl implements One
{
public static void main(String a[]){
System.out.println("hello");
}
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
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
Regards,
Manfred.
 
tvs sundaram
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Sandeep
SCJP2, OCSD(Oracle JDeveloper) OCED(Oracle Internet Platform)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic