aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes native?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "native??" Watch "native??" New topic
Author

native??

srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252
1) What will happen when you attempt to compile and run this code? [7]
public class Mod{
public static void main(String argv[]){
}
public static native void amethod();
}
(a)Error at compilation: native method cannot be static.
(b)Error at compilation native method must return value.
(c)Compilation but error at run time unless you have made code containing native amethod available.
(d)Compilation and execution without error.


here why c is not correct ...
suppose if the native code is not available then how the program run??
answer given is d ...how can ???


please correct me if iam wrong???

thanks

sri


Thanks & Regards<br /> <br />-Srikanth
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

suppose if the native code is not available then how the program run??
Note that the native method is never called in that example. Since the method would be linked dynamically at runtime *if* it were called, there is no error message, and the code runs fine.

Hope this helps.
srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252
so u mean to say steve that whether native method is written in some other language or not there wont be any compile or runtime error...??


thanks

sri
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

so u mean to say steve that whether native method is written in some other language or not there wont be any compile or runtime error...??

Correct. You can easily verify this by compiling and running a class that declares - but does not call - a native method with no linkable native code.
srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252
thanks steve ...
thats what the answer says that there would have been runtime exception if u had called the method explicitly....

thanks

sri......
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: native??
 
Similar Threads
native
methods question
native methods
Question from Marcus Green mock exam..
native method