1. class A {
2. public String toString () {
3. return “4”;
4. }
5. }
6. class B extends A {
7. public String toString () {
8. return super.toString() + “3”;
9. }
10. }
11. public class Test {
12. public static void main(String[]args) {
13. System.out.printIn(new B());
14. }
15. }
What is the result?()
A. Compilation succeeds and 4 is printed.
B. Compilation succeeds and 43 is printed.
C. An error on line 9 causes compilation to fail.
D. An error on line 14 causes compilation to fail.
E. Compilation succeeds but an exception is thrown at line 9.
您可能感兴趣的试卷
你可能感兴趣的试题
A. Member data have no access modifiers.
B. Member data can be modified directly.
C. The access modifier for methods is protected.
D. The access modifier to member data is private.
E. Methods provide for access and modification of data.
public class Test {
public static void main (String [] args) {
string foo = “blue”;
string bar = foo;
foo = “green”;
System.out.printIn(bar);
}
}
What is the result?()
A. An exception is thrown.
B. The code will not compile.
C. The program prints “null”
D. The program prints “blue”
E. The program prints “green”
2. public class Foo implements Runnable (
3. public void run (Thread t) {
4. system.out.printIn(“Running.”);
5. }
6. public static void main (String[] args) {
7. new thread (new Foo()).start();
8. )
9. )
What is the result?()
A. An exception is thrown.
B. The program exists without printing anything.
C. An error at line 1 causes compilation to fail.
D. An error at line 6 causes the compilation to fail.
E. “Running” is printed and the program exits.
A. Exiting from a synchronized block.
B. Calling the wait method on an object.
C. Calling the notify method on an object.
D. Calling the notifyAll method on an object.
E. Calling the setPriority method on a thread object.
1. public class ForBar {
2. public static void main(String []args) {
3. int i = 0, j = 5;
4. tp: for (;;) {
5. i ++;
6. for(;;)
7. if(i > --j) break tp;
8. }
9. system.out.printIn(“i = ” + i + “, j = “+ j);
10. }
11. }
What is the result?()
A. The program runs and prints “i=1, j=0”
B. The program runs and prints “i=1, j=4”
C. The program runs and prints “i=3, j=4”
D. The program runs and prints “i=3, j=0”
E. An error at line 4 causes compilation to fail.
F. An error at line 7 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 = 3
B. Value = 4
C. Value = 5
D. Value = 6
E. Value = 7
F. Value = 8
public class ExceptionTest {
class TestException extends Exception {}
public void runTest () throws TestException {}
public void test () /* Point X*/ {
runTest ();
}
}
At point X on line 4, which code can be added to make the code compile?()
A. Throws Exception.
B. Catch (Exception e).
C. Throws RuntimeException.
D. Catch (TestException e).
E. No code is necessary.
1.public class Test {
2.public static void main (String args[]) {
3.class Foo {
4.public int i = 3;
5.}
6.Object o = (Object) new Foo();
7.Foo foo = (Foo)o;
8.System.out.printIn(foo. i);
9. }
10.}
What is the result?()
A. Compilation will fail.
B. Compilation will succeed and the program will print “3”
C. Compilation will succeed but the program will throw a ClassCastException at line 6.
D. Compilation will succeed but the program will throw a ClassCastException at line 7.
A. Final void methoda() {}
B. Void final methoda() {}
C. Static void methoda() {}
D. Static final void methoda() {}
E. Final abstract void methoda() {}
public class OuterClass {
private double d1 1.0;
//insert code here
}
You need to insert an inner class declaration at line2. Which two inner class declarations are valid?()
A. static class InnerOne { public double methoda() {return d1;} }
B. static class InnerOne { static double methoda() {return d1;} }
C. private class InnerOne { public double methoda() {return d1;} }
D. protected class InnerOne { static double methoda() {return d1;} }
E. public abstract class InnerOne { public abstract double methoda(); }
![](https://static.ppkao.com/ppmg/img/appqrcode.png)
最新试题
What is the result?()
What is the result?()
Which two statements are true?()
Which statement is true?()
Which statement is true about the set variable on line 12?()
Which statement is true?()
Which code, inserted at line 4, guarantees that this program will output [1, 2]?()
Which three changes should be made to adapt this class to be used safely by multiple threads?()
Given a class whose instances, when found in a collection of objects, are sorted by using the compareTo() method, which two statements are true?()
Which three will compile and run without exception?()