📄 tt.html
字号:
<br><br>
5. public static void main(String[] args) {
<br><br>
6. System.out.println(str1);
<br><br>
7. }
<br><br>
<br><br>
10. public static void main(int[] args) {
<br><br>
11. System.out.println(str2);
<br><br>
12. }
<br><br>
13. }
<br><br>
<br><br>
a. Duplicate method main(), compilation error at line 5.
<br><br>
b. Duplicate method main(), compilation error at line 10.
<br><br>
c. Prints "main method with String[] args".
<br><br>
d. Prints "main method with int[] args".
<br><br>
<br><br>
Q10
<br><br>
In the following applet, how many buttons will be displayed?
<br><br>
<br><br>
1. import java.applet.*;
<br><br>
2. import java.awt.*;
<br><br>
<br><br>
3. public class Q16 extends Applet {
<br><br>
4. Button okButton = new Button("Ok");
<br><br>
<br><br>
5. public void init() {
<br><br>
6. add(okButton);
<br><br>
7. add(okButton);
<br><br>
8. add(okButton);
<br><br>
9. add(okButton);
<br><br>
<br><br>
10. add(new Button("Cancel"));
<br><br>
14. add(new Button("Cancel"));
<br><br>
15. add(new Button("Cancel"));
<br><br>
16. add(new Button("Cancel"));
<br><br>
<br><br>
18. setSize(300,300);
<br><br>
19. }
<br><br>
20. }
<br><br>
<br><br>
a. 1 Button with label "Ok" and 1 Button with label "Cancel".
<br><br>
b. 1 Button with label "Ok" and 4 Buttons with label "Cancel".
<br><br>
c. 4 Buttons with label "Ok" and 1 Button with label "Cancel".
<br><br>
d. 4 Buttons with label "Ok" and 4 Buttons with label "Cancel".
<br><br>
<br><br>
Q11
<br><br>
What is the output of the following program?
<br><br>
<br><br>
1. class Test {
<br><br>
2. void show() {
<br><br>
3. System.out.println("non-static method in Test");
<br><br>
4. }
<br><br>
5. }
<br><br>
<br><br>
6. public class Q3 extends Test {
<br><br>
<br><br>
7. static void show() {
<br><br>
8. System.out.println("Overridden non-static method in Q3");
<br><br>
9. }
<br><br>
<br><br>
10. public static void main(String[] args) {
<br><br>
11. Q3 a = new Q3();
<br><br>
12. }
<br><br>
13 }
<br><br>
<br><br>
a. Compilation error at line 2.
<br><br>
b. Compilation error at line 7.
<br><br>
c. No compilation error, but runtime exception at line 2.
<br><br>
d. No compilation error, but runtime exception at line 7.
<br><br>
<br><br>
Q12
<br><br>
What will happen if you compile/run the following code?
<br><br>
<br><br>
1. public class Q21 {
<br><br>
2. int maxElements;
<br><br>
<br><br>
3. void Q21() {
<br><br>
4. maxElements = 100;
<br><br>
5. System.out.println(maxElements);
<br><br>
6. }
<br><br>
<br><br>
7. Q21(int i) {
<br><br>
8. maxElements = i;
<br><br>
9. System.out.println(maxElements);
<br><br>
10. }
<br><br>
<br><br>
11. public static void main(String[] args) {
<br><br>
12. Q21 a = new Q21();
<br><br>
13. Q21 b = new Q21(999);
<br><br>
14.
<br><br>
15. }
<br><br>
16. }
<br><br>
<br><br>
a. Prints 100 and 999.
<br><br>
b. Prints 999 and 100.
<br><br>
c. Compilation error at line 2, variable maxElements was not initialized.
<br><br>
d. Compilation error at line 12.
<br><br>
<br><br>
Q13
<br><br>
Given the following class definition, which of the following methods could be legally placed after the comment //Here
<br><br>
<br><br>
1. public class Rid {
<br><br>
2. public void amethod(int i, String s){}
<br><br>
3. //Here
<br><br>
4. }
<br><br>
<br><br>
a. public void amethod(String s, int i) {}
<br><br>
b. public int amethod(int i, String s) {}
<br><br>
c. public void amethod(int i, String mystring) {}
<br><br>
d. public void Amethod(int i, String s) {}
<br><br>
<br><br>
Q14
<br><br>
Given the following class definition, which of the following statements would be legal after the comment //Here
<br><br>
<br><br>
1. class InOut {
<br><br>
2. String s= new String("Between");
<br><br>
<br><br>
3. public void amethod(final int iArgs) {
<br><br>
4. int iam;
<br><br>
5. class Bicycle{
<br><br>
6. public void sayHello(){
<br><br>
7. //Here
<br><br>
8. } //End of bicycle class
<br><br>
9. }
<br><br>
10. } //End of amethod
<br><br>
<br><br>
11. public void another(){
<br><br>
12. int iOther;
<br><br>
13. }
<br><br>
14. }
<br><br>
<br><br>
a. System.out.println(s);
<br><br>
b. System.out.println(iOther);
<br><br>
c. System.out.println(iam);
<br><br>
d. System.out.println(iArgs);
<br><br>
<br><br>
Q15
<br><br>
Which of the following methods are members of the Vector class and allow you to input a new element
<br><br>
<br><br>
a. addElement()
<br><br>
b. insert()
<br><br>
c. append()
<br><br>
d. addItem()
<br><br>
<br><br>
Q16
<br><br>
What will happen when we try to compile the following code.
<br><br>
<br><br>
1. public void WhichArray( Object x ) {
<br><br>
<br><br>
2. if( x instanceof int[] ) {
<br><br>
3. int[] n = (int[]) x ;
<br><br>
4. for( int i = 0 ; i < n.length ; i++ ){
<br><br>
5. System.out.println("integers = " + n[i] );
<br><br>
6. }
<br><br>
7. }
<br><br>
<br><br>
8. if( x instanceof String[] ) {
<br><br>
9. System.out.println("Array of Strings");
<br><br>
10. }
<br><br>
11. }
<br><br>
<br><br>
a. The compiler objects to line 2 comparing an Object with an array.
<br><br>
b. The compiler objects to line 3 casting an Object to an array of int primitives.
<br><br>
c. The compiler objects to line 7 comparing an Object to an array of Objects.
<br><br>
d. It compiles without error.
<br><br>
<br><br>
Q17
<br><br>
Consider the following class
<br><br>
<br><br>
1. class Tester {
<br><br>
2. void test (int i) { System.out.println ("int version"); }
<br><br>
3. void test (String s) { System.out.println ("String version"); }
<br><br>
4.
<br><br>
5. public static void main (String args[]) {
<br><br>
6. Tester c = new Tester ();
<br><br>
7. char ch = 'p';
<br><br>
8. c.test (ch);
<br><br>
9. }
<br><br>
10. }
<br><br>
<br><br>
Which of the following statements below is true?(Choose one.)
<br><br>
<br><br>
a. Line 3 will not compile, because void methods cannot be overridden.
<br><br>
b. Line 8 will not compile, because there is no conversion of test() that takes a char argument.
<br><br>
c. The code will compile and produce the follwing output "int version"
<br><br>
d. The code will compile and produce the follwing output "String version"
<br><br>
<br><br>
<br><br>
Q18
<br><br>
You are creating a ToolBase class which will be extended by other programmers. The ToolBase class contains a single abstract method, createTool.
<br><br>
<br><br>
Which of the following statements are true?
<br><br>
<br><br>
a. The ToolBase class must be declared abstract.
<br><br>
b. Classes extending ToolBase must not be declared abstract.
<br><br>
c. The ToolBase class must not be declared final.
<br><br>
d. The following variable declaration is illegal in any context "ToolBase myTB;"
<br><br>
<br><br>
Q19
<br><br>
Given the following hierarchical relationship of several classes.
<br><br>
<br><br>
1. Object
<br><br>
2. |---TypeA
<br><br>
3. | |-----TypeAB
<br><br>
4. | |-----TypeAC
<br><br>
5. |--------TypeY
<br><br>
<br><br>
And given the following method definition
<br><br>
<br><br>
6. public sayType(Object x ){
<br><br>
7. if(x instanceof Object )System.out.print("Object,");
<br><br>
8. if(x instanceof TypeA )System.out.print("TypeA,");
<br><br>
9. if(x instanceof TypeAB )System.out.print("TypeAB,");
<br><br>
10. if(x instanceof TypeAC )System.out.print("TypeAC,");
<br><br>
11. }
<br><br>
<br><br>
What would the program output be if the following line was executed
<br><br>
<br><br>
12. sayType( new TypeAB() );
<br><br>
<br><br>
a. Object,
<br><br>
b. Object,TypeA,TypeAB,
<br><br>
c. TypeAB,
<br><br>
d. Object,TypeAC,
<br><br>
<br><br>
Q20
<br><br>
What happens on trying to compile and run the following code?
<br><br>
<br><br>
1. public class EqualsTest{
<br><br>
2. public static void main(String args[]){
<br><br>
3. Long LA = new Long( 9 ) ;
<br><br>
4. Long LB = new Long( 9 ) ;
<br><br>
5. if( LA == LB ) System.out.println("Equal");
<br><br>
6. else System.out.println("Not Equal");
<br><br>
7. }
<br><br>
8. }
<br><br>
<br><br>
a. The program compiles but throws a runtime exception in line 5.
<br><br>
b. The program compiles and prints "Not Equal".
<br><br>
c. The program compiles and prints "Equal".
<br><br>
d. The program throws compilation error.
<br><br>
<br><br>
<br><br>
Q21
<br><br>
Which one statement in true about the application below?
<br><br>
<br><br>
1. class StaticStuff {
<br><br>
2. static int x = 10;
<br><br>
<br><br>
3. static { x += 5; }
<br><br>
<br><br>
4. public static void main(String args[]) {
<br><br>
5. System.out.println("x = " + x);
<br><br>
6. }
<br><br>
<br><br>
7. static { x /= 5; }
<br><br>
8. }
<br><br>
<br><br>
a. The code compiles, and execution produces the output x = 10.
<br><br>
b. The code compiles, and execution produces the output x = 15.
<br><br>
c. The code compiles, and execution produces the output x = 3.
<br><br>
d. Line 7 will not compile, because you can have only one static initializer.
<br><br>
<br><br>
Q22
<br><br>
Assume the the class AcLis implements the ActionListener interface. The code fragment below constructs a button ande gives it four action listeners. When the button is pressed, which action listener is the first to get its actionPerformed() method invoked?
<br><br>
<br><br>
1. Button btn = new Button("Hello");
<br><br>
2. AcLis a1 = new AcLis();
<br><br>
3. AcLis a2 = new AcLis();
<br><br>
4. AcLis a3 = new AcLis();
<br><br>
<br><br>
5. btn.addActionListener(a1);
<br><br>
6. btn.addActionListener(a2);
<br><br>
7. btn.addActionListener(a3);
<br><br>
8. btn.removeActionListener(a2);
<br><br>
9. btn.removeActionListener(a3);
<br><br>
10. btn.addActionListener(a3);
<br><br>
11. btn.addActionListener(a2);
<br><br>
<br><br>
a. a1 gets its actionPerformed() method invoked first.
<br><br>
b. a2 gets its actionPerformed() method invoked first.
<br><br>
c. a3 gets its actionPerformed() method invoked first.
<br><br>
d. It is impossible to know which listener will be first.
<br><br>
<br><br>
Q23
<br><br>
Which statement or statements are true about the code listed below?
<br><br>
<br><br>
1. public class MyTextArea extends TextArea {
<br><br>
2. public MyTextArea(int nrows, int ncols) {
<br><br>
3. enableEvents(AWTEvent.TEXT_EVENT_MASK);
<br><br>
4. }
<br><br>
<br><br>
5. public void processTextEvent(TextEvent te) {
<br><br>
6. System.out.println("Processing a text event");
<br><br>
7. }
<br><br>
8. }
<br><br>
<br><br>
a. The source code must appear in a file called MyTextArea.java.
<br><br>
b. Between lines 2 and 3, a call should be made to super(nrows,ncols) so that the next component will have the correct size.
<br><br>
c. Between lines 6 and 7, the following code should appear "return true;"
<br><br>
d. Between lines 6 and 7, the following code should appear "super.processTextEvent(te);"
<br><br>
<br><br>
Q24
<br><br>
Which statement or statements are true about the code fragment listed below? (HINT The ActionListener and ItemListener interface each define a single method.)
<br><br>
<br><br>
1. class MyListener implements ActionListener, ItemListener {
<br><br>
2. public void actionPerformed(ActionEvent e) {
<br><br>
3. System.out.println("Action.");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -