|
{ int i = 99; public void amethod() { System.out.println("Base.amethod()"); } Base() { amethod(); } } public class Derived extends Base { int i = -1; public static void main(String argv[]) { Base b = new Derived(); System.out.println(b.i); b.amethod(); } public void amethod() { System.out.println("Derived.amethod()"); } } Choices: What will happen when you attempt to compile and run the following code? class Base { int i = 99; public void amethod() { System.out.println("Base.amethod()"); } Base() { amethod(); } } public class Derived extends Base { int i = -1; public static void main(String argv[]) { Base b = new Derived(); System.out.println(b.i); b.amethod(); } public void amethod() { System.out.println("Derived.amethod()"); } } Choices: A.Derived.amethod() -1 Derived.amethod() B.Derived.amethod() 99 C.Compile time error D.Derived.amethod() 10: What is the result when you compile and run the following code? public class ThrowsDemo { static void throwMethod() { System.out.println("Inside throwMethod."); throw new IllegalAccessException("demo"); } public static void main(String args[]) { try { throwMethod(); } catch (IllegalAccessException e) { System.out.println("Caught " + e); } } } Choices: What is the result when you compile and run the following code? public class ThrowsDemo { static void throwMethod() { System.out.println("Inside throwMethod."); throw new IllegalAccessException("demo"); } public static void main(String args[]) { try { throwMethod(); } catch (IllegalAccessException e) { System.out.println("Caught " + e); } } } Choices: A.Compilation error B.Runtime error C.Compile successfully, nothing is printed. D.Inside throwMethod. followed by caught:java.lang.IllegalAccessExcption: demo 11:What is written to the standard output given the following statement:System.out.println(4|7); Select the right answer: A.4 B.5 C.6 D.7 12: Give the code fragment: if(x>4){ System.out.println(“Test 1”);} else if (x>9){ System.out.println(“Test 2”);} else { System.out.println(“Test 3”);} Which range of value x would produce of output “Test 2”? Give the code fragment: if(x>4){ System.out.println(“Test 1”);} else if (x>9){ System.out.println(“Test 2”);} else { System.out.println(“Test 3”);} Which range of value x would produce of output “Test 2”? A.x<4 B.x>4 C.x>9 D.None 13: The following code is entire contents of a file called Example.java,causes precisely one error during compilation: class SubClass extends BaseClass{ } class BaseClass(){ String str; public BaseClass(){ System.out.println(“ok”);} public BaseClass(String s){ str=s;}} public class Example{ public void method(){ SubClass s=new SubClass(“hello”); BaseClass b=new BaseClass(“world”); } } Which line would be cause the error? The following code is entire contents of a file called Example.java,causes precisely one error during compilation: (责任编辑:职场达人) |


