现有: 1. class Book { 2. private final void read() { System.out.print("book "); } 3. } 4. class Page extends Book { 5. public static void main(String [] args) { 6. // insert code here 7. } 8. private final void read() { System.out.print("page "); } 9. } 和如下三个代码片段 ( x, y, z ): x. // just a comment y. new Page().read(); z. new Book().read(); 分别插入到第6行,有几个允许代码通过编译并可以运行且无异常?()
第1题:
Which declarations will allow a class to be started as a standalone program?()
第2题:
现有: 1. class HorseRadish { 2. // insert code here 3. protected HorseRadish(int x) { 4. System.out.println("bok choy"); 5. } 6. } 7. class Wasabi extends HorseRadish { 8. public static void main(String [] args) { 9. Wasabi w = new Wasabi(); 10. } 11. } 分别插入到第 2 行,哪两项允许代码编译并产生"bok choy" 输出结果?()
第3题:
现有2 个文件: 1. package x; 2. public class X { 3. public static void doX() { System.out.print("doX "); } 4. } 和: 1. class Find { 2. public static void main(String [] args) { 3. //insert code here 4. } 5. } 哪两行分别插入到类Find 的第3 行将编译并产生输出“doX”? ()
第4题:
1. class Calc { 2. public static void main(String [] args) { 3. try { 4. int x = Integer.parseInt("42a"); 5. //insert code here 6. System.out.print("oops "); 7. } 8. } 9. } 下面哪两行分别插入到第五行,会导致输出“oops”?()
第5题:
1. class MyThread implements Runnable { 2. public void run() { 3. System.out.print("go "); 4. } 5. 6. public static void main(String [] args) { 7. // insert code here 8. t.start(); 9. } 10. } 和如下四句: Thread t = new MyThread(); MyThread t = new MyThread(); Thread t = new Thread(new Thread()); Thread t = new Thread(new MyThread()); 分别插入到第5行,有几个可以通过编译?()
第6题:
Given classes defined in two different files: 1. package util; 2. public class BitUtils { 3. private static void process(byte[] b) { } 4. } 1. package app; 2. public class SomeApp { 3. public static void main(String[] args) { 4. byte[] bytes = new byte[256]; 5. // insert code here 6. } 7. } What is required at line 5 in class SomeApp to use the process method of BitUtils?()
第7题:
1. public class enclosingone ( 2. public class insideone{} 3. ) 4. public class inertest( 5. public static void main (string[]args)( 6. enclosingone eo= new enclosingone (); 7. //insert code here 8. ) 9. ) Which statement at line 7 constructs an instance of the inner class?()
第8题:
现有: 1. interface Animal { 2. void eat(); 3. } 4. 5. // insert code here 6. 7. public class HouseCat extends Feline { 8. public void eat() { } 9. } 和五个声明: abstract class Feline implements Animal { } abstract class Feline implements Animal { void eat(); } abstract class Feline implements Animal { public void eat(); } abstract class Feline implements Animal { public void eat() { } } abstract class Feline implements Animal { abstract public void eat(); } 分别插入到第5行,有几个可以通过编译?()
第9题:
现有: 1. interface Animal { 2. void eat(); 3. } 4. 5. // insert code here 6. 7. public class HouseCat implements Feline { 8. public void eat() { } 9. } 和以下三个接口声明: interface Feline extends Animal { } interface Feline extends Animal { void eat(); } interface Feline extends Animal { void eat() { } } 分别插入到第 5 行,有多少行可以编译?()
第10题:
process(bytes);
BitUtils.process(bytes);
app.BitUtils.process(bytes);
util.BitUtils.process(bytes);
import util.BitUtils. *; process(bytes);
SomeApp cannot use the process method in BitUtils.
第11题:
0
1
2
3
第12题:
Class A
Compilation fails.
An exception is thrown at line 2.
An exception is thrown at line 6.
The code executes with no output.
第13题:
1. public class A { 2. void A() { 3. System.out.println(“Class A”); 4. } 5. public static void main(String[] args) { 6. new A(); 7. } 8. } What is the result?()
第14题:
1. class Pizza { 2. java.util.ArrayList toppings; 3. public final void addTopping(String topping) { 4. toppings.add(topping); 5. } 6. } 7. public class PepperoniPizza extends Pizza { 8. public void addTopping(String topping) { 9. System.out.println(”Cannot add Toppings”); 10. } 11. public static void main(String[] args) { 12. Pizza pizza = new PepperoniPizza(); 13. pizza.addTopping(”Mushrooms”); 14. } 15. } What is the result?()
第15题:
现有: 1. class Book { 2. private final void read() { System.out.print("book "); } 3. } 4. class Page extends Book { 5. public static void main(String [] args) { 6. // insert code here 7. } 8. private final void read() { System.out.print("page "); } 9. } 和如下三个代码片段( x, y, z ): x. // just a comment y. new Page().read(); z. new Book().read(); 分别插入到第6行,有几个允许代码通过编译并可以运行且无异常?()
第16题:
1. class Passer2 { 2. //insert code here 3. static int bigState = 42; 4. public static void main(String [] args) { 5. bigState = p2.go(bigState); 6. System.out.print(bigState); 7. } 8. int go(int x) { 9. return ++x; 10. } 11. } 和4段代码片段: static Passer2 p2 = new Passer2(); final static Passer2 p2 = new Passer2(); private static Passer2 p2 = new Passer2(); final private static Passer2 p2 = new Passer2(); 有多少行分别插入到第2行,可以编译?()
第17题:
final class Tree { private static String tree = "tree "; String getTree() { return tree; } } class Elm extends Tree { private static String tree = "elm "; public static void main(String [] args) { new Elm().go(new Tree()); } void go(Tree t) { String s = t.getTree()+Elm.tree+tree+(new Elm().getTree()); System.out.println(s); } } 结果为:()
第18题:
Given classes defined in two different files: 1. package util; 2. public class BitUtils { 3. public static void process(byte[]) { /* more code here */ } 4. } 1. package app; 2. public class SomeApp { 3. public static void main(String[] args) { 4. byte[] bytes = new byte[256]; 5. // insert code here 6. } 7. } What is required at line 5 in class SomeApp to use the process method of BitUtils?()
第19题:
Given a class Repetition: 1. package utils; 2. 3. public class Repetition { 4. public static String twice(String s) { return s + s; } 5. } and given another class Demo: 1. // insert code here 2. 3. public class Demo { 4. public static void main(String[] args) { 5. System.out.println(twice(”pizza”)); 6. } 7. } Which code should be inserted at line 1 of Demo.java to compile and run Demo to print“pizzapizza”?()
第20题:
1. import java.util.*; 2. 3. Class FindStuff { 4. public static void main(String [] args) { 5. // insert code here 6. c.put("x", 123); 7. } 8. } 分别插入到第5行,哪三行允许代码编译?()
第21题:
现有 1. class Calc { 2. public static void main(String [] args) { 3. try { 4. int x = Integer.parselnt ("42a") ; 5. //insert code here 6. System.out.print ("oops"); 7. } 8. } 9. } 下面哪两行分别插入到第五行,会导致输 "oops" ? ()
第22题:
} catch (ClassCastException c) {
} catch (IllegalStateException c) {
} catch (NumberFormatException n) {
} catch (IllegalArgumentException e) {
第23题:
InsideOnew ei= eo.new InsideOn();
Eo.InsideOne ei = eo.new InsideOne();
InsideOne ei = EnclosingOne.new InsideOne();
EnclosingOne.InsideOne ei = eo.new InsideOne();
第24题:
} catch (IllegalArgumentException e) {
} catch (IllegalStateException c) {
} catch (NumbelFormatException n) {
} catch (ClassCastException c) {