Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about native

 
wei liu
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 150)
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

Compilation error - implimentations can never be native.
Compilation error - method not found in local libraries.
Runtime Exception - method not found in local libraries.
Compilation successfull but runtime error is thrown if and only if the method someMethod of class One_impl is called.
the ans is 4th. why? i donot know much about native method.is it important in the real exam? if it is ,where can i get the tutorial stuff online?
 
Jim Hall
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as the exam is concerned, I think that you should know the correct way to declare a native method. By providing the native modifier you are saying that its implementation is provided outside the JVM. So the method is declared similarly to an abstract method or interface method (no implementation body).
 
Jane Griscti
Ranch Hand
Posts: 3141
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add to Jim's comment. The compiler doesn't look for the implementation of a native method so no error will be raised if the method is declared correctly.
The runtime will not look for a native method until it is explicitly invoked; at which point it will ask the operating system to supply the implementation. If the method is not on the system; a runtime error will result.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Co-author Mike Meyers' Java 2 Certification Passport
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic