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(); }
A. The default constructor initializes method variables.
B. The default constructor invokes the no-parameter constructor of the superclass.
C. The default constructor initializes the instance variables declared in the class.
D. If a class lacks a no-parameter constructor,, but has other constructors, the compiler creates a default constructor.
E. The compiler creates a default constructor only when there are no other constructors for the class.
A. Public
B. Private
C. Protected
D. Transient
E. No access modifier is required.
A. Abstract public void methoda();
B. Public abstract double methoda();
C. Static void methoda(double d1){}
D. Public native double methoda() {}
E. Protected void methoda(double d1) {}
//point X
public class foo {
public static void main (String[]args) throws Exception {
java.io.printWriter out = new java.io.PrintWriter {
new java.io.outputStreamWriter (System.out), true;
out.printIn(“Hello”);
}
}
}
Which statement at PointX on line 1 allows this code to compile and run?()
A. Import java.io.*;
B. Include java.io.*;
C. Import java.io.PrintWriter;
D. Include java.io.PrintWriter;
E. No statement is needed.
public class Foo {
public void main (String [] args) {
system.out.printIn(“Hello World.”);
}
}
What is the result?()
A. An exception is thrown.
B. The code does no compile.
C. “Hello World.” Is printed to the terminal.
D. The program exits without printing anything.
1. public class Test {
2. public static void main (String []args) {
3. unsigned byte b = 0;
4. b--;
5.
6. }
7. }
What is the value of b at line 5?()
A. -1
B. 255
C. 127
D. Compilation will fail.
E. Compilation will succeed but the program will throw an exception at line 4.
最新试题
What is the appropriate definition of the hashCode method in class Person?()
What is the result?()
Which two can be results?()
Given that t1 is a reference to a live thread, which is true?()
What is the result?()
Which three will compile and run without exception?()
What is the result?()
Which code, inserted at line 4, guarantees that this program will output [1, 2]?()
Which two statements are true?()
What is the output if the main() method is run?()