11. public class Test {
12. public void foo() {
13. assert false;
14. assert false;
15. }
16. public void bar(){
17. while(true){
18. assert false;
19. }
20. assert false;
21. }
22. }
What causes compilation to fail?()
A. Line 13
B. Line 14
C. Line 18
D. Line 20
您可能感兴趣的试卷
你可能感兴趣的试题
interface Beta {}
class Alpha implements Beta {
String testIt() {
return “Tested”;
}
}
public class Main1 {
static Beta getIt() {
return new Alpha();
}
public static void main( String[] args ) {
Beta b = getIt();
System.out.println( b.testIt() );
}
}
What is the result?()
A. Tested
B. Compilation fails.
C. The code runs with no output.
D. An exception is thrown at runtime.
1. class Bar { }
1. class Test {
2. Bar doBar() {
3. Bar b = new Bar();
4. return b;
5. }
6. public static void main (String args[]) {
7. Test t = new Test();
8. Bar newBar = t.doBar();
9. System.out.println(“newBar”);
10. newBar = new Bar();
11. System.out.println(“finishing”);
12. }
13. }
At what point is the Bar object, created on line 3, eligible for garbage collection?()
A. After line 8.
B. After line 10.
C. After line 4, when doBar() completes.
D. After line 11, when main() completes.
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 A
B. 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.
20. public float getSalary(Employee e) {
21. assert validEmployee(e);
22. float sal = lookupSalary(e);
23. assert (sal>0);
24. return sal;
25. }
26. private int getAge(Employee e) {
27. assert validEmployee(e);
28. int age = lookupAge(e);
29. assert (age>0);
30. return age;
31. }
Which line is a violation of appropriate use of the assertion mechanism?()
A. line 21
B. line 23
C. line 27
D. line 29
1. class Exc0 extends Exception { }
2. class Exc1 extends Exc0 { }
3. public class Test {
4. public static void main(String args[]) {
5. try {
6. throw new Exc1();
7. } catch (Exc0 e0) {
8. System.out.println(“Ex0 caught”);
9. } catch (Exception e) {
10. System.out.println(“exception caught”);
11. }
12. }
13. }
What is the result?()
A. Ex0 caught
B. exception caught
C. Compilation fails because of an error at line 2.
D. Compilation fails because of an error at line 6.
A. public
B. private
C. protected
D. transient
E. default access
public class X {
public static void main(String [] args) {
try {
badMethod();
System.out.print(“A”);
}
catch (Exception ex) {
System.out.print(“C”);
}
finally {
System.out.print(“B”);
}
System.out.print(“D”);
}
public static void badMethod() {
throw new Error();
}
}
What is the result?()
A. ABCD
B. Compilation fails.
C. C is printed before exiting with an error message.
D. BC is printed before exiting with an error message.
E. BCD is printed before exiting with an error message.
public class X {
public X aMethod() { return this;}
}
public class Y extends X {
}
Which two methods can be added to the definition of class Y?()
A. public void aMethod() {}
B. private void aMethod() {}
C. public void aMethod(String s) {}
D. private Y aMethod() { return null; }
E. public X aMethod() { return new Y(); }
A. assert (!(map.contains(x))); map.add(x);
B. if (x > 0){}else { assert (x==0); }
C. public void aMethod(int x) { assert (x > 0); }
D. assert (invariantCondition()); return retval;
E. switch (x) { case 1: break; case 2: creak; default: assert (x == 0);
int i = 1,j = 10;
do{
if (i>j) {
continue;
}
j--;
} while (++i <6);
System.out.println(“i = “ +i+” and j = “+j);
What is the result?()
A. i = 6 and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 4
D. i = 5 and j = 6
E. i = 6 and j = 6
最新试题
Which two of statements are true?()
What is the result?()
What can be a result?()
What is the result?()
Which three changes should be made to adapt this class to be used safely by multiple threads?()
Which three will compile and run without exception?()
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?()
Given: foo and bar are public references available to many other threads, foo refers to a Thread and bar is an Object. The thread foo is currently executing bar.wait(). From another thread, what provides the most reliable way to ensure that foo will stop executing wait()?()
Given that t1 is a reference to a live thread, which is true?()
What is the output if the main() method is run?()