单选题1. public class Boxer1 { 2. Integer i; 3. int x; 4. public Boxer1(int y) { 5. x=i+y; 6. System.out.println(x); 7. } 8. public static void main(String[] args) { 9. new Boxer1(new Integer(4)); 10. } 11. } What is the result?()A The value “4” is printed at the command line.B Compilation fails because of an error in line 5.C Compilation fails because of an error in line 9.D A NullPointerException occurs at runtime.E A NumberFormatException occurs at runtime.F An IllegalStateException occurs at runtime.
单选题
1. public class Boxer1 { 2. Integer i; 3. int x; 4. public Boxer1(int y) { 5. x=i+y; 6. System.out.println(x); 7. } 8. public static void main(String[] args) { 9. new Boxer1(new Integer(4)); 10. } 11. } What is the result?()
A
The value “4” is printed at the command line.
B
Compilation fails because of an error in line 5.
C
Compilation fails because of an error in line 9.
D
A NullPointerException occurs at runtime.
E
A NumberFormatException occurs at runtime.
F
An IllegalStateException occurs at runtime.
参考解析
解析:
暂无解析
相关考题:
以下程序的运行结果为:1. public class Conditional {2. public static void main(String args [] ) {3. int x = 4;4. System.out.println( "value is " +((x >4、? 99.99 : 9));5. }6. } A. 输出:value is 99.99B. 输出: value is 9C. 输出: value is 9.0D. 在第4行出现编译错误
1. class A { 2. public int getNumber(int a) { 3. return a + 1; 4. } 5. } 6. 7. class B extends A { 8. public int getNumber (int a) { 9. return a + 2 10. } 11. 12. public static void main (String args[]) { 13. A a = new B(); 14. System.out.printIn(a.getNumber(0)); 15. } 16. } What is the result?() A、 Compilation succeeds and 1 is printed.B、 Compilation succeeds and 2 is printed.C、 An error at line 8 causes compilation to fail.D、 An error at line 13 causes compilation to fail.E、 An error at line 14 causes compilation to fail.
在Java中,下列代码将输出()。 1. public class integerequals 2. { 3. public static void main (String args[]) 4. { 5. Integer a= new Integer(3); 6. Integer b= new Integer(3); 7. System.out.println(a==b); 8. } 9. } A、编译器将显示第7行有错误B、程序编译并打印trueC、程序编译并打印falseD、程序编译但在第7行引起了一个运行期意外
1. public class SimpleCalc { 2. public int value; 3. public void calculate() { value += 7; } 4. } And: 1. public class MultiCalc extends SimpleCalc { 2. public void calculate() { value -= 3; } 3. public void calculate(int multiplier) { 4. calculate(); 5. super.calculate(); 6. value *=multiplier; 7. } 8. public static void main(String[] args) { 9. MultiCalc calculator = new MultiCalc(); 10. calculator.calculate(2); 11. System.out.println(”Value is: “+ calculator.value); 12. } 13. } What is the result?() A、 Value is: 8B、 Compilation fails.C、 Value is: 12D、 Value is: -12E、 The code runs with no output.F、 An exception is thrown at runtime.
1. public class X implements Runnable( 2. private int x; 3. private int y; 4. 5. public static void main(String[]args) 6. X that = new X(); 7. (new Thread(that)).start(); 8. (new Thread(that)).start(); 9. ) 10. 11. public void run() ( 12. for (;;) ( 13. x++; 14. y++; 15. System.out.printIn(“x=” + x + “, y = ” + y); 16. ) 17. ) What is the result?()A、 Errors at lines 7 and 8 cause compilation to fail.B、 The program prints pairs of values for x and y that might not always be the same on the same line (for example, “x=2, y=1”).C、 The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=1, y=1”).D、 The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears only for once (for example, “x=1, y=1” followed by “x=2, y=2”).
public class Test { public static void add3 (Integer i) { int val = i.intValue(); val += 3; i = new Integer(val); } public static void main(String args[]) { Integer i = new Integer(0); add3(i); System.out.println(i.intValue()); } } What is the result? () A、 0B、 3C、 Compilation fails.D、 An exception is thrown at runtime.
1. public class Target { 2. private int i = 0; 3. public int addOne() { 4. return ++i; 5. } 6. } And: 1. public class Client { 2. public static void main(String[] args) { 3. System.out.println(new Target().addOne()); 4. } 5. } Which change can you make to Target without affecting Client?() A、 Line 4 of class Target can be changed to return i++;B、 Line 2 of class Target can be changed to private int i = 1;C、 Line 3 of class Target can be changed to private int addOne() {D、 Line 2 of class Target can be changed to private Integer i = 0;
1. public class A { 2. public void doit() { 3. } 4. public String doit() { 5. return “a”; 6. } 7. public double doit(int x) { 8. return 1.0; 9. } 10.} What is the result?() A、 An exception is thrown at runtime.B、 Compilation fails because of an error in line 7.C、 Compilation fails because of an error in line 4.D、 Compilation succeeds and no runtime errors with class A occur.
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?() A、 Class AB、 Compilation fails.C、 An exception is thrown at line 2.D、 An exception is thrown at line 6.E、 The code executes with no output.
1. public class X { 2. public static void main (String[]args) { 3. int [] a = new int [1] 4. modify(a); 5. System.out.printIn(a[0]); 6. } 7. 8. public static void modify (int[] a) { 9. a[0] ++; 10. } 11. } What is the result?()A、 The program runs and prints “0”B、 The program runs and prints “1”C、 The program runs but aborts with an exception.D、 An error “possible undefined variable” at line 4 causes compilation to fail.E、 An error “possible undefined variable” at line 9 causes compilation to fail.
1. public class SwitchTest { 2. public static void main (String []args) { 3. System.out.PrintIn(“value =” +switchIt(4)); 4. } 5. public static int switchIt(int x) { 6. int j = 1; 7. switch (x) { 8. case 1: j++; 9. case 2: j++; 10. case 3: j++; 11. case 4: j++; 12. case 5: j++; 13. default:j++; 14. } 15. return j + x; 16. } 17. } What is the output from line 3?() A、 Value = 3B、 Value = 4C、 Value = 5D、 Value = 6E、 Value = 7F、 Value = 8
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?() A、 Compilation fails.B、 Cannot add ToppingsC、 The code runs with no output.D、 A NullPointerException is thrown in Line 4.
1. public class Test { 2. public static String output =””; 3. 4. public static void foo(int i) { 5. try { 6. if(i==1) { 7. throw new Exception(); 8. } 9. output += “1”; 10. } 11. catch(Exception e) { 12. output += “2”; 13. return; 14. } 15. finally { 16. output += “3”;17. } 18. output += “4”; 19. } 20. 21. public static void main(String args[]) { 22. foo(0); 23. foo(1); 24. 25. }26. } What is the value of the variable output at line 23?()
1. public class Boxer1 { 2. Integer i; 3. int x; 4. public Boxer1(int y) { 5. x=i+y; 6. System.out.println(x); 7. } 8. public static void main(String[] args) { 9. new Boxer1(new Integer(4)); 10. } 11. } What is the result?() A、 The value “4” is printed at the command line.B、 Compilation fails because of an error in line 5.C、 Compilation fails because of an error in line 9.D、 A NullPointerException occurs at runtime.E、 A NumberFormatException occurs at runtime.F、 An IllegalStateException occurs at runtime.
1. import java.util.*; 2. public class Example { 3. public static void main(String[] args) { 4. // insert code here 5. set.add(new integer(2)); 6. set.add(new integer(l)); 7. System.out.println(set); 8. } 9. } Which code, inserted at line 4, guarantees that this program will output [1,2]? ()A、 Set set = new TreeSet();B、 Set set = new HashSet();C、 Set set = new SortedSet();D、 List set = new SortedList();E、 Set set = new LinkedHashSet();
1. public class test ( 2. public static void main(string args[]) { 3. int 1= 0; 4. while (i) { 5. if (i==4) { 6. break; 7. } 8. ++i; 9. } 10. 11. } 12. ) What is the value of i at line 10?()A、 0B、 3C、 4D、 5E、 The code will not compile.
1. public class A { 2. public String doit(int x, int y) { 3. return “a”; 4. } 5. 6. public String doit(int... vals) { 7. return “b”; 8. } 9. } Given: 25. A a=new A(); 26. System.out.println(a.doit(4, 5)); What is the result?() A、 Line 26 prints “a” to System.out.B、 Line 26 prints „b” to System.out.C、 An exception is thrown at line 26 at runtime.D、 Compilation of class A will fail due to an error in line 6.
单选题1. public class X { 2. public static void main (String[]args) { 3. int [] a = new int [1] 4. modify(a); 5. System.out.printIn(a[0]); 6. } 7. 8. public static void modify (int[] a) { 9. a[0] ++; 10. } 11. } What is the result?()A The program runs and prints “0”B The program runs and prints “1”C The program runs but aborts with an exception.D An error “possible undefined variable” at line 4 causes compilation to fail.E An error “possible undefined variable” at line 9 causes compilation to fail.
单选题1. public class A { 2. public String doit(int x, int y) { 3. return “a”; 4. } 5. 6. public String doit(int... vals) { 7. return “b”; 8. } 9. } Given: 25. A a=new A(); 26. System.out.println(a.doit(4, 5)); What is the result?()A Line 26 prints “a” to System.out.B Line 26 prints „b” to System.out.C An exception is thrown at line 26 at runtime.D Compilation of class A will fail due to an error in line 6.
单选题1. public class test ( 2. public static void main(string args[]) { 3. int 1= 0; 4. while (i) { 5. if (i==4) { 6. break; 7. } 8. ++i; 9. } 10. 11. } 12. ) What is the value of i at line 10?()A 0B 3C 4D 5E The code will not compile.
单选题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?()A Compilation fails.B Cannot add ToppingsC The code runs with no output.D A NullPointerException is thrown in Line 4.
单选题1. public class SimpleCalc { 2. public int value; 3. public void calculate() { value += 7; } 4. } And: 1. public class MultiCalc extends SimpleCalc { 2. public void calculate() { value -= 3; } 3. public void calculate(int multiplier) { 4. calculate(); 5. super.calculate(); 6. value *=multiplier; 7. } 8. public static void main(String[] args) { 9. MultiCalc calculator = new MultiCalc(); 10. calculator.calculate(2); 11. System.out.println(”Value is: “+ calculator.value); 12. } 13. } What is the result?()A Value is: 8B Compilation fails.C Value is: 12D Value is: -12E The code runs with no output.F An exception is thrown at runtime.
单选题1. public class SwitchTest { 2. public static void main (String []args) { 3. System.out.PrintIn(“value =” +switchIt(4)); 4. } 5. public static int switchIt(int x) { 6. int j = 1; 7. switch (x) { 8. case 1: j++; 9. case 2: j++; 10. case 3: j++; 11. case 4: j++; 12. case 5: j++; 13. default:j++; 14. } 15. return j + x; 16. } 17. } What is the output from line 3?()A Value = 3B Value = 4C Value = 5D Value = 6E Value = 7F Value = 8
单选题public class Test { public static void add3 (Integer i) { int val = i.intValue(); val += 3; i = new Integer(val); } public static void main(String args[]) { Integer i = new Integer(0); add3(i); System.out.println(i.intValue()); } } What is the result? ()A 0B 3C Compilation fails.D An exception is thrown at runtime.
单选题1. class A { 2. public int getNumber(int a) { 3. return a + 1; 4. } 5. } 6. 7. class B extends A { 8. public int getNumber (int a) { 9. return a + 2 10. } 11. 12. public static void main (String args[]) { 13. A a = new B(); 14. System.out.printIn(a.getNumber(0)); 15. } 16. } What is the result?()A Compilation succeeds and 1 is printed.B Compilation succeeds and 2 is printed.C An error at line 8 causes compilation to fail.D An error at line 13 causes compilation to fail.E An error at line 14 causes compilation to fail.
单选题1. public class Target { 2. private int i = 0; 3. public int addOne() { 4. return ++i; 5. } 6. } And: 1. public class Client { 2. public static void main(String[] args) { 3. System.out.println(new Target().addOne()); 4. } 5. } Which change can you make to Target without affecting Client?()A Line 4 of class Target can be changed to return i++;B Line 2 of class Target can be changed to private int i = 1;C Line 3 of class Target can be changed to private int addOne() {D Line 2 of class Target can be changed to private Integer i = 0;
单选题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?()A Class AB Compilation fails.C An exception is thrown at line 2.D An exception is thrown at line 6.E The code executes with no output.