SCJP模拟题 AND Answer[2](3)

2019-08-30 12:58

1. Object 2. |---TypeA 3. | |-----TypeAB 4. | |-----TypeAC 5. |--------TypeY

And given the following method definition

6. public sayType(Object x ){

7. if(x instanceof Object )System.out.print(\8. if(x instanceof TypeA )System.out.print(\9. if(x instanceof TypeAB )System.out.print(\10. if(x instanceof TypeAC )System.out.print(\11. }

What would the program output be if the following line was executed 12. sayType( new TypeAB() );

a. Object,

b. Object,TypeA,TypeAB, c. TypeAB, d. Object,TypeAC, Q20

What happens on trying to compile and run the following code?

1. public class EqualsTest{

2. public static void main(String args[]){ 3. Long LA = new Long( 9 ) ; 4. Long LB = new Long( 9 ) ;

5. if( LA == LB ) System.out.println(\6. else System.out.println(\7. } 8. }

a. The program compiles but throws a runtime exception in line 5. b. The program compiles and prints \c. The program compiles and prints \d. The program throws compilation error.

Q21

Which one statement in true about the application below? 1. class StaticStuff { 2. static int x = 10;

3. static { x += 5; }

4. public static void main(String args[]) { 5. System.out.println(\6. }

7. static { x /= 5; } 8. }

a. The code compiles, and execution produces the output x = 10. b. The code compiles, and execution produces the output x = 15. c. The code compiles, and execution produces the output x = 3.

d. Line 7 will not compile, because you can have only one static initializer. Q22

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?

1. Button btn = new Button(\2. AcLis a1 = new AcLis(); 3. AcLis a2 = new AcLis(); 4. AcLis a3 = new AcLis();

5. btn.addActionListener(a1); 6. btn.addActionListener(a2); 7. btn.addActionListener(a3); 8. btn.removeActionListener(a2); 9. btn.removeActionListener(a3); 10. btn.addActionListener(a3); 11. btn.addActionListener(a2);

a. a1 gets its actionPerformed() method invoked first. b. a2 gets its actionPerformed() method invoked first.

c. a3 gets its actionPerformed() method invoked first. d. It is impossible to know which listener will be first. Q23

Which statement or statements are true about the code listed below?

1. public class MyTextArea extends TextArea { 2. public MyTextArea(int nrows, int ncols) { 3. enableEvents(AWTEvent.TEXT_EVENT_MASK); 4. }

5. public void processTextEvent(TextEvent te) { 6. System.out.println(\7. } 8. }

a. The source code must appear in a file called MyTextArea.java.

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.

c. Between lines 6 and 7, the following code should appear \

d. Between lines 6 and 7, the following code should appear \

Q24

Which statement or statements are true about the code fragment listed below? (HINT The ActionListener and ItemListener interface each define a single method.)

1. class MyListener implements ActionListener, ItemListener { 2. public void actionPerformed(ActionEvent e) { 3. System.out.println(\4. }

5. public void itemStateChanged(ItemEvent ie) { 6. System.out.println(\7. } 8. }

a. The code compiles without error.

b. The code generates a compiler error at line 1. c. The code generates a compiler error at line 2. d. The code generates a compiler error at line 5.

Q25

A text field has a variable-width font. It is constructed by calling new TextField(\What happens if you change the contents of the textfield to \narrowest characters, and w is one of the widest.) a. The text field becomes wider. b. The text field becomes narrower.

c. The text field stays the same width; to see the entire contents you have to scroll using -> and <-.

d. The text field stays the same width; to see you need to have a horizontal scroll bar. Q26

Which statements about garbage collection are true? Select all valid answers a. You can directly free the memory allocated by an object. b. You can directly run the garbage collector whenever you want.

c. The garbage collector informs your object when it is about to be garbage collected. d. The garbage collector runs in low-memory situations. Q27

The setForeground() and setBackground() methods are defined in the following class a. Graphics b. Container c. Component d. Applet

Q28

What methods does JAVA define in the java.lang.Math class specifically for trigonometric calculations? Select all valid answers. a. cos() b. asin() c. arctan() d. sine() Q29

Imagine that there are two exception classes called Exception1 and Exception2 that descend from the Exception class. Given these two class definitions, 1. class First {

2. void test() throws Exception1, Exception2 { . . . } 3. }

4. class Second extends First { 5. void test() { . . . }

Create a class called Third that extends Second and defines a test() method. What exceptions can Third's test method throw? Select all valid answers.

a. Exception1 b. Exception2

c. no checked exceptions

d. any exceptions declared in the throws clause of the Third's test() method. Q30

Given these code snippets,

1. Boolean b1 = new Boolean(true); 2. Boolean b2 = new Boolean(true);

which expressions are legal JAVA expressions that return true? Select all valid answers. a. b1 == b2 b. b1.equals(b2) c. b1 & b2 d. b1 || b2 Q31

What will appear in the standard output when you run the Tester class?

1. class Tester { 2. int var;

3. Tester(double var) { 4. this.var = (int)var; 5. }

6. Tester(int var) { 7. this(\8. }

9. Tester(String s) { 10. this();

11. System.out.println(s); 12. }


SCJP模拟题 AND Answer[2](3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:自考混凝土及砌体结构模拟试题A卷(附答案)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: