📄 mockcert06.txt
字号:
2. for (int k = 0; j + k != 10; j++, k++) {
3. System.out.println("j is " + j + " k is " + k);
4. }
4) 1. int j = 0;
2. do {
3. System.out.println("j is " + j++);
4. if (j == 3) { continue loop; }
5. } while (j < 10)
Question 44
===========================================================
What would be the output from this code fragment?
1. int x = 0, y = 4, z = 5;
2. if (x > 2) {
3. if (y < 5) {
4. System.out.println("message one");
5. }
6. else {
7. System.out.println("message two");
8. }
9. }
10. else if (z > 5) {
11. System.out.println("message three");
12. }
13. else {
14. System.out.println("message four");
15. }
Only One:
1) message one
2) message two
3) message three
4) message four
Question 45
===========================================================
Which statement is true about the following code fragment?
1. int j = 2;
2. switch (j) {
3. case 2:
4. System.out.println("value is two");
5. case 2 + 1:
6. System.out.println("value is three");
7. break;
8. default:
9. System.out.println("value is " + j);
10. break;
11. }
Only One:
1) The code is illegal because of the expression at line 5.
2) The acceptable types for the variable j, as the argument to the switch() construct, could be any of byte, short, int, or long.
3) The output would be only the text value is two.
4) The output would be the text value is two followed by the text value is three.
5) The output would be the text value is two, followed by the text value is three, followed by the text value is 2.
Question 46
===========================================================
Consider the following class hierarchy and code fragment:
java.lang.Exception
\
java.io.IOException
/ \
java.io.StreamCorruptedException java.net.MalformedURLException
1. try {
2. // assume s is previously defined
3. URL u = new URL(s);
4. // in is an ObjectInputStream
5. Object o = in.readObject();
6. System.out.println("Success");
7. }
8. catch (MalformedURLException e) {
9. System.out.println("Bad URL");
10. }
11. catch (StreamCorruptedException e) {
12. System.out.println("Bad file contents");
13. }
14. catch (Exception e) {
15. System.out.println("General exception");
16. }
17. finally {
18. System.out.println("Doing finally part");
19. }
20. System.out.println("Carrying on");
What lines are output if the constructor at line 3 throws a MalformedURLException?
Mutiple:
1) Bad URL
2) Bad file contents
3) General exception
4) Doing finally part
5) Carrying on
Question 47
===========================================================
Consider the following class hierarchy and code fragment:
java.lang.Exception
\
java.io.IOException
/ \
java.io.StreamCorruptedException java.net.MalformedURLException
1. try {
2. // assume s is previously defined
3. URL u = new URL(s);
4. // in is an ObjectInputStream
5. Object o = in.readObject();
6. System.out.println("Success");
7. }
8. catch (MalformedURLException e) {
9. System.out.println("Bad URL");
10. }
11. catch (StreamCorruptedException e) {
12. System.out.println("Bad file contents");
13. }
14. catch (Exception e) {
15. System.out.println("General exception");
16. }
17. finally {
18. System.out.println("Doing finally part");
19. }
20. System.out.println("Carrying on");
What lines are output if the methods at lines 3 and 5 complete successfully without throwing any exceptions?
Mutiple:
1) Success
2) Bad file contents
3) General exception
4) Doing finally part
5) Carrying on
Question 48
===========================================================
Consider the following class hierarchy and code fragment:
java.lang.Throwable
/ \
java.lang.Error java.lang.Exception
/ \
java.lang.OutOfMemoryError java.io.IOException
/ \
java.io.StreamCorruptedException java.net.MalformedURLException
1. try {
2. // assume s is previously defined
3. URL u = new URL(s);
4. // in is an ObjectInputStream
5. Object o = in.readObject();
6. System.out.println("Success");
7. }
8. catch (MalformedURLException e) {
9. System.out.println("Bad URL");
10. }
11. catch (StreamCorruptedException e) {
12. System.out.println("Bad file contents");
13. }
14. catch (Exception e) {
15. System.out.println("General exception");
16. }
17. finally {
18. System.out.println("Doing finally part");
19. }
20. System.out.println("Carrying on");
What lines are output if the method at line 5 throws an OutOfMemoryError?
Only One:
1) Success
2) Bad URL
3) Bad file contents
4) General exception
5) Doing finally part
Question 49
===========================================================
Which one of the following fragments shows the most appropriate way to throw an exception? Assume that any undeclared variables have been appropriately declared elsewhere and are in scope and have meaningful values.
Mutiple:
1) 1. Exception e = new IOException("File not found");
2. if (!f.exists()) { // f is a File object
3. throw e;
4. }
2) 1. if (!f.exists()) { // f is a File object
2. throw new IOException("File " + f.getName() + " not found");
3. }
3) 1. if (!f.exists()) {
2. throw IOException;
3. }
4) 1. if (!f.exists()) {
2. throw "File not found";
3. }
5) 1. if (!f.exists()) { // f is a File object
2. throw new IOException();
3. }
Question 50
===========================================================
Consider this class:
1. public class Test1 {
2. public float aMethod(float a, float b) {
3. }
4.
5. }
Which of the following methods would be legal if added (individually) at line 4?
Mutiple:
1) public int aMethod(int a, int b) { }
2) public float aMethod(float a, float b) { }
3) public float aMethod(float a, float b, int c) throws Exception { }
4) public float aMethod(float c, float d) { }
5) private float aMethod(int a, int b, int c) { }
Question 51
===========================================================
Consider these classes, defined in separate source files:
1. public class Test1 {
2. public float aMethod(float a, float b)
3. throws IOException {
4. }
5. }
1. public class Test2 extends Test1 {
2.
3. }
Which of the following methods would be legal (individually) at line 2 in class Test2?
Mutiple:
1) float aMethod(float a, float b) { }
2) public int aMethod(int a, int b) throws Exception { }
3) public float aMethod(float a, float b) throws Exception { }
4) public float aMethod(float p, float q) { }
Question 52
===========================================================
You have been given a design document for a veterinary registration system for implementation in Java. It states:
"A pet has an owner, a registration date, and a vaccination-due date. A cat is a pet that has a flag indicating whether it has been neutered, and a textual description of its markings."
Given that the Pet class has already been defined, which of the following fields would be appropriate for inclusion in the Cat class as members?
Mutiple:
1) Pet thePet;
2) Date registered;
3) Date vaccinationDue;
4) boolean neutered;
5) String markings;
Question 53
===========================================================
Consider the following classes, declared in separate source files:
1. public class Base {
2. public void method(int i) {
3. System.out.println("Value is " + i);
4. }
5. }
1. public class Sub extends Base {
2. public void method(int j) {
3. System.out.println("This value is " + j);
4. }
5. public void method(String s) {
6. System.out.println("I was passed " + s);
7. }
8. public static void main(String args[]) {
9. Base b1 = new Base();
10. Base b2 = new Sub();
11. b1.method(5);
12. b2.method(6);
13. }
14. }
What output results when the main method of the class Sub is run?
Only One:
1) Value is 5
Value is 6
2) This value is 5
This value is 6
3) Value is 5
This value is 6
4) This value is 5
Value is 6
5) I was passed 5
I was passed 6
Question 54
===========================================================
Consider the following class definition:
1. public class Test extends Base {
2. public Test(int j) {
3. }
4. public Test(int j, int k) {
5. super(j, k);
6. }
7. }
Which of the following are legitimate calls to construct instances of the Test class?
Mutiple:
1) Test t = new Test();
2) Test t = new Test(1);
3) Test t = new Test(1, 2);
4) Test t = new Test(1, 2, 3);
5) Test t = (new Base()).new Test(1);
Question 55
===========================================================
Consider the following class definition:
1. public class Test extends Base {
2. public Test(int j) {
3. }
4. public Test(int j, int k) {
5. super(j, k);
6. }
7. }
Which of the following forms of constructor must exist explicitly in the definition of the Base class?
Mutiple:
1) Base() { }
2) Base(int j) { }
3) Base(int j, int k) { }
4) Base(int j, int k, int l) { }
Question 56
===========================================================
Which of the following statements are true? (Choose one or more.)
Mutiple:
1) An inner class may be declared private.
2) An inner class may be declared static.
3) An inner class defined in a method should always be anonymous.
4) An inner class defined in a method can access all the method local variables.
5) Construction of an inner class may require an instance of the outer class.
Question 57
===========================================================
Consider the following definition:
1. public class Outer {
2. public int a = 1;
3. private int b = 2;
4. public void method(final int c) {
5. int d = 3;
6. class Inner {
7. private void iMethod(int e) {
8.
9. }
10. }
11. }
12. }
Which variables may be referenced correctly at line 8?
Mutiple:
1) a
2) b
3) c
4) d
5) e
Question 58
===========================================================
Which of the following statements are correct?
Mutiple:
1) Given that Inner is a non-static class declared inside a public class Outer, and appropriate constructor forms are defined, an instance of Inner may be constructed like this:
new Outer().new Inner()
2) If an anonymous inner class inside the class Outer is defined to implement the interface ActionListener, it may be constructed like this:
new Outer().new ActionListener()
3) Given that Inner is a non-static class declared inside a public class Outer and appropriate constructor forms are defined, an instance of Inner may be constructed in a static method like this:
new Inner()
4) An anonymous class instance that implements the interface MyInterface may be constructed and returned from a method like this:
1. return new MyInterface(int x) {
2. int x;
3. public MyInterface(int x) {
4. this.x = x;
5. }
6. };
Question 59
===========================================================
Which one statement below is true concerning the following code?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -