Question 7)
What will happen when you attempt to compile and run this code?
public class Mod{public static void main(String argv[]){ } public static native void amethod();}
1) Error at compilation: native method cannot be static
2) Error at compilation native method must return value
3) Compilation but error at run time unless you have made code containing native amethod available
4) Compilation and execution without error
Question 8)
What will happen when you attempt to compile and run this code?
private class Base{}public class Vis{ transient int iVal; public static void main(String elephant[]){ }}
1)Compile time error: Base cannot be private
2)Compile time error indicating that an integer cannot be transient
3)Compile time error transient not a data type
4)Compile time error malformed main method
Question 9)
What happens when you attempt to compile and run these two files in the same directory?
//File P1.javapackage MyPackage;class P1{void afancymethod(){ System.out.println("What a fancy method"); }}//File P2.javapublic class P2 extends P1{ public static void main(String argv[]){ P2 p2 = new P2(); p2.afancymethod(); }}
1) Both compile and P2 outputs "What a fancy method" when run
2) Neither will compile
3) Both compile but P2 has an error at run time
4) P1 compiles cleanly but P2 has an error at compile time
责任编辑:cyth