11. public static void main(String[] args) {
12. Object obj =new int[] { 1,2,3 };
13. int[] someArray = (int[])obj;
14. for (int i: someArray) System.out.print(i +“ “)
15. }
What is the result? ()
A. 1 2 3
B. Compilation fails because of an error in line 12.
C. Compilation fails because of an error in line 13.
D. Compilation fails because of an error in line 14.
E. A ClassCastException is thrown at runtime.
您可能感兴趣的试卷
你可能感兴趣的试题
11. public enum Title {
12. MR(”Mr.”), MRS(”Mrs.”), MS(”Ms.”);
13. private final String title;
14. private Title(String t) { title = t; }
15. public String format(String last, String first) {
16. return title + “ “ + first + “ “ + last;
17. }
18. }
19. public static void main(String[] args) {
20. System.out.println(Title.MR.format(”Doe”, “John”));
21. }
What is the result?()
A. Mr. John Doe
B. An exception is thrown at runtime.
C. Compilation fails because of an error in line 12.
D. Compilation fails because of an error in line 15.
E. Compilation fails because of an error in line 20.
public class Ball {
public enum Color { RED, GREEN, BLUE };
public void foo() {
// insert code here
{ System.out.println(c); }
}
}
Which code inserted at line 14 causes the foo method to print RED, GREEN, and BLUE?()
A. for( Color c : Color.values())
B. for( Color c = RED; c <= BLUE; c++)
C. for( Color c; c.hasNext() ; c.next())
D. for( Color c = Color[0]; c <= Color[2]; c++)
E. for( Color c = Color.RED; c <= Color.BLUE; c++)
A. static final int[] a = { 100,200 };
B. static final int[] a; static { a=new int[2]; a[0]=100; a[1]=200; }
C. static final int[] a = new int[2] { 100,200 };
D. static final int[] a; static void init() { a = new int[3]; a[0]=100; a[1]=200; }
35. String #name = “Jane Doe”;
36. int$age=24;
37. Double_height = 123.5;
38. double~temp = 37.5;
Which two are true?()
A. Line 35 will not compile.
B. Line 36 will not compile.
C. Line 37 will not compile.
D. Line 38 will not compile.
55. int []x= {1, 2,3,4, 5};
56. int y[] =x;
57. System.out.println(y[2]);
Which is true?()
A. Line 57 will print the value 2.
B. Line 57 will print the value 3.
C. Compilation will fail because of an error in line 55.
D. Compilation will fail because of an error in line 56.
1. public class Test {
2. int x= 12;
3. public void method(int x) {
4. x+=x;
5. System.out.println(x);
6. }
7. }
Given:
34. Test t = new Test();
35. t.method(5);
What is the output from line 5 of the Test class?()
A. 5
B. 10
C. 12
D. 17
E. 24
public static void parse(String str) {
try {
float f= Float.parseFloat(str);
} catch (NumberFormatException nfe) {
f= 0;
} finally {
System.out.println(f);
}
}
public static void main(String[] args) {
parse(”invalid”);
}
What is the result?()
A. 0.0
B. Compilation fails.
C. A ParseException is thrown by the parse method at runtime.
D. A NumberFormatException is thrown by the parse method at runtime.
1. public class GoTest {
2. public static void main(String[] args) {
3. Sente a = new Sente(); a.go();
4. Goban b = new Goban(); b.go();
5. Stone c = new Stone(); c.go();
6. }
7. }
8.
9. class Sente implements Go {
10. public void go() { System.out.println(”go in Sente.”); }
11. }
12.
13. class Goban extends Sente {
14. public void go() { System.out.println(”go in Goban”); }
15. }
16.
17. class Stone extends Goban implements Go { }
18.
19. interface Go { public void go(); }
What is the result?()
A. go in Goban go in Sente go in Sente
B. go in Sente go in Sente go in Goban
C. go in Sente go in Goban go in Goban
D. go in Goban go in Goban go in Sente
E. Compilation fails because of an error in line 17.
public abstract class Shape {
private int x;
private int y;
public abstract void draw();
public void setAnchor(int x, int y) {
this.x = x;
this.y = y;
}
}
Which two classes use the Shape class correctly?()
A. public class Circle implements Shape { private int radius; }
B. public abstract class Circle extends Shape { private int radius; }
C. public class Circle extends Shape { private int radius; public void draw(); }
D. public abstract class Circle implements Shape { private int radius; public void draw(); }
E. public class Circle extends Shape { private int radius;public void draw() {/* code here */} }
F. public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }
interface Data { public void load(); }
abstract class Info { public abstract void load(); }
Which class correctly uses the Data interface and Info class?()
A. public class Employee extends Info implements Data { public void load() { /*do something*/ } }
B. public class Employee implements Info extends Data { public void load() { /*do something*/ } }
C. public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }
D. public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }
E. public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }
F. public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }
![](https://static.ppkao.com/ppmg/img/appqrcode.png)
最新试题
What is the result?()
What is the appropriate definition of the hashCode method in class Person?()
What is the result?()
What is the output if the main() method is run?()
Given that t1 is a reference to a live thread, which is true?()
Which three will compile and run without exception?()
Which statement is true?()
Which two are possible results?()
Given that Triangle implements Runnable, and:Which two statements, inserted independently at both lines 35 and 41, tend to allow both threads to temporarily pause and allow the other thread to execute?()
Which code, inserted at line 4, guarantees that this program will output [1, 2]?()