• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

interface again

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic