• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

native

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello every1,
Here is the code
interface One
{
public void someMethod();
}
public class One_impl implements One
{
public native void someMethod();
}
Assuming that the native method is not provided in any local library, an
attempt to compile and run the above lines of code will cause
1. Compilation error - implimentations can never be native.
2. Compilation error - method not found in local libraries.
3. Runtime Exception - method not found in local libraries.
4. Compilation successfull but runtime error is thrown if and only if the
method someMethod of class One_impl is called.

Answer is 4:
I thought that as the interface is extended and its given that the native method is not provided in library, then it would b compiler error. Can any one explain me why the answer is 4
 
Enthuware Software Support
Posts: 4895
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you make a method native, you do not give the implementation and the compiler assumes that the implementation will be available at the runtime. The interface implementation requirement is also satisfied because as far as the compiler is concered, the method is implementated.
So, there is no compile time error.
-Paul.

------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus
 
Friends help you move. Good friends help you move bodies. This tiny ad will help:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic