📄 tt.html
字号:
<br><br>
<br><br>
5. Window grid = new Frame();
<br><br>
6. grid.setLayout(new GridLayout(0,1,2,3));
<br><br>
<br><br>
7. for(int i=0;i<labels.length;i++) {
<br><br>
8. grid.add(new Button(labels[i]));
<br><br>
9. }
<br><br>
10. grid.pack();
<br><br>
11. grid.setVisible(true);
<br><br>
12. }
<br><br>
<br><br>
Select the one right answer
<br><br>
a. The program will not show any buttons at all.
<br><br>
b. It will place all buttons in one row - A B C D E F.
<br><br>
c. It will place all buttons in one column, i.e., each button in a separate row - A B C D E and F.
<br><br>
d. It will place pairs of buttons in three separate row A B, C D and E F.
<br><br>
<br><br>
Q67
<br><br>
What happens when this method is called with an input of "Java rules"?
<br><br>
<br><br>
1. public String addOK(String S) {
<br><br>
2. S += " OK!";
<br><br>
3. return S;
<br><br>
4. }
<br><br>
<br><br>
Select one correct answer
<br><br>
a. The method will return "OK!";
<br><br>
b. A runtime exception will be thrown.
<br><br>
c. The method will return "Java rules OK!".
<br><br>
d. The method will return "Java rules".
<br><br>
<br><br>
<br><br>
Q68
<br><br>
What happens during execution of the following program?
<br><br>
<br><br>
1. public class OperandOrder {
<br><br>
2. public static void main(String args[]) {
<br><br>
3. int i=0;
<br><br>
4. int a[] = {3,6};
<br><br>
5. a[i] = i = 9;
<br><br>
6. System.out.println(i + " " + a[0] + " " + a[1]);
<br><br>
7. }
<br><br>
8. }
<br><br>
<br><br>
Select one correct answer.
<br><br>
a. Raises "ArrayIndexOutOfBoundsException".
<br><br>
b. Prints "9 9 6".
<br><br>
c. Prints "9 0 6".
<br><br>
d. Prints "9 3 6".
<br><br>
<br><br>
Q69
<br><br>
Which statements about the output of the following program are true?
<br><br>
<br><br>
1. public class Logic {
<br><br>
2. public static void main(String args[]) {
<br><br>
3. int i = 0;
<br><br>
4. int j = 0;
<br><br>
5. boolean t = true;
<br><br>
6. boolean r;
<br><br>
<br><br>
7. r = (t & 0<(i += 1));
<br><br>
8. r = (t && 0<(i += 2));
<br><br>
9. r = (t | 0<(j += 1));
<br><br>
10. r = (t || 0<(j += 2));
<br><br>
11. System.out.println(i + " " + j);
<br><br>
12. }
<br><br>
13. }
<br><br>
<br><br>
Select all the valid answers.
<br><br>
a. The first digit printed is 1.
<br><br>
b. The first digit printed is 3.
<br><br>
c. The second digit printed is 3.
<br><br>
d. The second digit printed is 1.
<br><br>
<br><br>
Q70
<br><br>
What kind of stream is the System.out object?
<br><br>
a. java.io.BufferedWriter
<br><br>
b. java.io.PrintStream
<br><br>
c. java.io.FileWriter
<br><br>
d. java.io.OutputStreamWriter
<br><br>
<br><br>
Q71
<br><br>
Which of the following events has a matching adapter class that implements the appropriate listener interface?
<br><br>
<br><br>
Select all correct answers.
<br><br>
a. java.awt.event.MouseEvent
<br><br>
b. java.awt.event.ActionEvent
<br><br>
c. java.awt.event.FocusEvent
<br><br>
d. java.awt.event.ItemEvent
<br><br>
<br><br>
Q72
<br><br>
Here is a partial listing of a class to represent a game board in a networked game. It is desired to prevent collisions due to more than one Thread using the addPic method to modify the array of Image references.
<br><br>
<br><br>
1. class Board extends Object {
<br><br>
2. Image[] pics = new Image[64];
<br><br>
3. int active = 0;
<br><br>
<br><br>
4. public boolean addPic( Image mg, int pos) {
<br><br>
5. synchronized (this) {
<br><br>
6. if (pics[pos] == null)
<br><br>
7. { active++ ; pics[pos] = mg; return true; }
<br><br>
8. else
<br><br>
9. return false;
<br><br>
10. }
<br><br>
11. }
<br><br>
12. // remainder of class
<br><br>
<br><br>
Select all the alternatives for line 5 that would accomplish this.
<br><br>
a. synchronized (this)
<br><br>
b. synchronized (pics)
<br><br>
c. synchronized (mg)
<br><br>
d. synchronized (active)
<br><br>
<br><br>
Q73
<br><br>
Given an object created by the following class
<br><br>
<br><br>
1. class Example extends Object {
<br><br>
2. public void Increment (Integer N) {
<br><br>
3. N = new Integer( N.intValue() + 1);
<br><br>
4. }
<br><br>
<br><br>
6. public void Result(int x) {
<br><br>
7. Integer X = new Integer(x);
<br><br>
8. Increment(X);
<br><br>
9. System.out.println("New value is" + X);
<br><br>
10. }
<br><br>
<br><br>
11. }
<br><br>
<br><br>
What happens when a program calls the Result method with a value of 30?
<br><br>
a. The message "New value is 31" goest to the standard output.
<br><br>
b. The message "New value is 29" goes to the standard output.
<br><br>
c. The message "New Value is 30" goes to the standard output.
<br><br>
d. The program fails to compile.
<br><br>
<br><br>
Q74
<br><br>
What is the output of the following program
<br><br>
<br><br>
1. public class Test {
<br><br>
2. private int i = giveMeJ();
<br><br>
3. private int j = 10;
<br><br>
4.
<br><br>
5. private int giveMeJ() {
<br><br>
6. return j;
<br><br>
7. }
<br><br>
8.
<br><br>
9. public static void main(String args[]) {
<br><br>
10. System.out.println((new AQuestion()).i);
<br><br>
11. }
<br><br>
12. }
<br><br>
<br><br>
Select one correct answer
<br><br>
a. Compiler error complaining about access restriction of private variables of AQuestion.
<br><br>
b. Compiler error complaining about forward referencing.
<br><br>
c. No Compilation error - The output is 0;
<br><br>
d. No Compilation error - The output is 10;
<br><br>
<br><br>
Q75
<br><br>
What is the result of compiling the following program
<br><br>
<br><br>
1. public class Test {
<br><br>
2. public static void main(String args[]) {
<br><br>
3. System.out.println("Before Try");
<br><br>
4. try {
<br><br>
5. } catch(java.io.IOException t) {
<br><br>
6. System.out.println("Inside Catch");
<br><br>
7. }
<br><br>
8. System.out.println("At the End");
<br><br>
9. }
<br><br>
10. }
<br><br>
<br><br>
Select one correct answer
<br><br>
a. No Compilation Error.
<br><br>
b. Compiler error complaining about the catch block where no IOException object can ever be thrown.
<br><br>
c. Compiler error - IOException not found. It must be imported in the first line of the code.
<br><br>
d. No compiler error. The lines "Before Try" and "At the end" are printed on the screen.
<br><br>
<br><br>
Q76
<br><br>
Read the following snippet carefully
<br><br>
<br><br>
1. public synchronized void someMethod() {
<br><br>
2. //lots of code
<br><br>
3. try {
<br><br>
4. Thread.sleep(500);
<br><br>
5. } catch(InterruptedException e) {
<br><br>
6. //do some things here.
<br><br>
7. }
<br><br>
8. //more and more code here
<br><br>
9. }
<br><br>
<br><br>
Select all correct answers
<br><br>
a. The code causes compilation error - sleep cannot be called inside synchronized methods.
<br><br>
b. The Thread sleeps for at least 500 milliseconds in this method if not interrupted.
<br><br>
c. When the thread "goes to sleep" it releases the lock on the object.
<br><br>
d. The "sleeping" Threads always have the lock on the Object.
<br><br>
<br><br>
<br><br>
<br><br>
Q77
<br><br>
What will be the result of attempt to compile and the run the following code
<br><br>
<br><br>
1. public class ADirtyOne {
<br><br>
2. public static void main(String args[]) {
<br><br>
3. System.out.println(Math.abs(Integer.MIN_VALUE));
<br><br>
4. }
<br><br>
5. }
<br><br>
<br><br>
Select one correct answer
<br><br>
a. Causes a compilation error.
<br><br>
b. Causes no error and the value printed on the screen is less than zero.
<br><br>
c. Causes no error and the value printed on the screen is one more than Integer.MAX_VALUE
<br><br>
d. Will throw a runtime exception due to overflow - Integer.MAX_VALUE is less in magnitue than Integer.MIN_VALUE.
<br><br>
<br><br>
<br><br>
Q78
<br><br>
What is the result of attempting to compile and run the following program
<br><br>
<br><br>
1. public class Test {
<br><br>
<br><br>
2. public void method(Object o) {
<br><br>
3. System.out.println("Object Version");
<br><br>
4. }
<br><br>
<br><br>
5. public void method(String s) {
<br><br>
6. System.out.println("String Version");
<br><br>
7. }
<br><br>
<br><br>
8. public static void main(String args[]) {
<br><br>
9. Test test = new Test();
<br><br>
10. test.method(null);
<br><br>
11. }
<br><br>
12. }
<br><br>
<br><br>
Select one correct answer
<br><br>
a. The code does not compile.
<br><br>
b. The code compiles cleanly and shows "Object Version".
<br><br>
c. The code compiles cleanly and shows "String Version".
<br><br>
d. The code throws an Exception at Runtime.
<br><br>
<br><br>
Q79
<br><br>
What is the result of attempting to compile the following program
<br><br>
<br><br>
1. public class Test {
<br><br>
<br><br>
2. public void method(StringBuffer sb) {
<br><br>
3. System.out.println("StringBuffer Verion");
<br><br>
4. }
<br><br>
<br><br>
5. public void method(String s) {
<br><br>
6. System.out.println("String Version");
<br><br>
7. }
<br><br>
<br><br>
8. public static void main(String args[]) {
<br><br>
9. Test test = new Test();
<br><br>
10. test.method(null);
<br><br>
11. }
<br><br>
12. }
<br><br>
<br><br>
Select one correct answer
<br><br>
a. The code does not compile.
<br><br>
b. The code compiles correctly and shows "StringBuffer Version".
<br><br>
c. The code compiles correctly and shows "String Version".
<br><br>
d. The code throws an Exception at Runtime.
<br><br>
<br><br>
Q80
<br><br>
What is the requirement of the class which implements the following Interface
<br><br>
<br><br>
1. public interface Test {
<br><br>
2. void someMethod();
<br><br>
3. }
<br><br>
<br><br>
Select all correct answers
<br><br>
a. Should have someMethod which must be necessarily declared as public.
<br><br>
b. Should have someMethod which could be "friendly" or public
<br><br>
c. Should have someMethod which should not throw any checked exceptions.
<br><br>
d. Should have someMethod which cannot be sychronized as sychronized is not in the signature of the interface definition.
<br><br>
<br><br>
Q81
<br><br>
What is the result of attempting to compile and run the following program?
<br><br>
<br><br>
1. public class AStringQuestion {
<br><br>
2. static String s1;
<br><br>
3. static String s2;
<br><br>
<br><br>
4. public static void main(String args[]) {
<br><br>
5. s2 = s1+s2;
<br><br>
6. System.out.println(s2);
<br><br>
7. }
<br><br>
8. }
<br><br>
<br><br>
[Select one correct answer]
<br><br>
a. Will cause a compilation error.
<br><br>
b. Runtime Execption - NullPointerException in the 2nd line of the main method.
<br><br>
c. Will compile successfully and print "nullnull" on the screen.
<br><br>
d. Will compile successfully and print an empty line on the screen.
<br><br>
<br><br>
Q82
<br><br>
What is the result of attempting to compile and run the following program?
<br><br>
<br><br>
1. import java.io.*;
<br><br>
<br><br>
2. public class OutOut {
<br><br>
3. public static void main(String args[]) throws IOException {
<br><br>
4. PrintStream pr = new PrintStream(new FileOutputStream("outfile"));
<br><br>
5. System.out = pr;
<br><br>
6. System.out.println("Lets see what I s
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -