Java认证模考试题_第1页
Java认证模考试题_第2页
Java认证模考试题_第3页
Java认证模考试题_第4页
Java认证模考试题_第5页
已阅读5页,还剩51页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Java认证模考试题 作者:佚名发表时间:2004-5-27 22:14:08阅读: 331 Java 2 TESTQuestion: 1Given the following code:class Testprivate int m;public static void fun() / some code.How can the member variable m be accessible directly in the method fun()?A. change private int m to protected int mB. change private int m to pub

2、lic int mC. change private int m to static int mD. change private int m to int m Explanation: If the variable m is changed to be a static variable it can be accessible in the method fun() for this method is a static member method. Correct Answer: C 1 of 60 Question: 2Which methods are correct overlo

3、ading methods of the following method: public void example().A. public void example( int m).B. public int example().C. public void example2().D. public int example ( int m, float f). Explanation: The overloading methods must have the same names. If only the return type of the methods are different i

4、t is sufficient tell the methods from each other. The arguments of the methods must be different enough to determine which method to call. Correct Answer: A,D 2 of 60 Question: 3Given the following fragment of code:public class Baseint w, x, y ,z;public Base(int a,int b)x=a; y=b;public Base(int a, i

5、nt b, int c, int d)/ assignment x=a, y=bw=d;z=c;Which expressions can be used at the point of / assignment x=a, y=b?A. Base(a,b);B. x=a, y=b;C. x=a; y=b;D. this(a,b); Explanation: In the second constructor, the call this(a,b) passes control the version of the constructor that takes two int arguments

6、. Correct Answer: C,D 3 of 60 Question: 4 Given the following definition:String s = story;Which of the following expressions are legal?A. s += books;B. char c = s1;C. int len = s.length;D. String t = s.toLowerCase(); Explanation: Answer B is not correct for String is a class and canT be treated as a

7、n array of char. Answer C is not correct for s.length() should be used, not s.length. Correct Answer: A,D 4 of 60 Question: 5What is the return value of the main() method in Java?A. StringB. intC. charD. void Explanation: The main() method in Java returns void. Correct Answer: D 5 of 60 Question: 6W

8、hich are the valid identifiers in Java?A. fieldnameB. superC. 3numberD. #numberE. $number Explanation: Valid identifiers in Java can start with a letter, underscore (_), or dollar sign ($), but not with digits or other signs. And identifiers can not be keywords.Correct Answer: A,E 6 of 60 Question:

9、7Which are valid Java keywords?A. constB. NULLC. falseD. thisE. native Explanation: All the keywords in Java are lowercase. goto and const are keywords that are not used in Java programming language. Correct Answer: A,C,D,E 7 of 60 Question: 8Which are valid integral expressions in Java?A. 22B. 0 x2

10、2C. 022D. 22H Explanation: In Java integral has three forms: decimal, octal and hexadecimal. Octal values start with a zero and hexadecimal values start with 0 x. Correct Answer: A,B,C 8 of 60 Question: 9Which one of the following ranges of short is correct?Explanation: The length of the short data

11、is 16 bits. The range of short is The length of the short data is 16 bits. The range of short is Correct Answer: D 9 of 60 Question: 10Which one of the following ranges of byte is correct?Correct Answer: B 10 of 60 Question: 11Given the following fragment of code, what are results of i and j after e

12、xecution?int i = 1;int j;j = i+;A. 1, 1B. 1, 2C. 2, 1D. 2, 2 Explanation: Pay attention to the position of the operator +. In this question, first j is assigned to 1, then the value of i is added to 2. Correct Answer: C 11 of 60 Question: 12Which of the following statements are true?A. is the arithm

13、etic right shift operator.B. is the logical right shift operator.C. is the arithmetic right shift operator.D. is the logical right shift operator. Explanation: There are two right shift operators in Java. They are and . is the arithmetic(signed) right shift operator and is the logical(unsigned) righ

14、t shift operator. Correct Answer: A,D 12 of 60 Question: 13Which of the following assignments are legal?A. float a = 2.0B. double b = 2.0C. int c = 2D. long d = 2 Explanation: In Java the default data type of floating point is double, not float. The assignment from double to float requires an explic

15、it cast. Correct Answer: B,C,D 13 of 60 Question: 14Which one of the following arguments is the correct argument of the main() method?A. char argsB. char argsC. String argD. String args Explanation: The argument of the main() method is an array of String. Then only answer C is an array of String. Co

16、rrect Answer: C 14 of 60 Question: 15Which one of the following is correct to create an array?A. float f = new float66;B. float f = new float66;C. float f = new float6;D. float f = new float66;E. float f = new float6; Explanation: In Java the declaration format allows the square brackets to be at th

17、e left or right of the variable name. But the new float6 is illegal. Correct Answer: A,B,D,E 15 of 60 Question: 16Given the following expression: int m = 0, 1, 2, 3, 4, 5, 6 ;Which result of the following expressions equals to the number of the array elements?A. m.length()B. m.lengthC. m.length()+1D

18、. m.length+1 Explanation: The number of elements in an array is stored in the length attribute in the array object. Correct Answer: B 16 of 60 Question: 17Given the following command to run a correct class: java MyTest a b cWhich statements are true?A. args0 = MyTest a b cB. args0 = MyTestC. args0 =

19、 aD. args1= b Explanation: The three arguments a b c are stored in the args array of the main() method. Then args0= a, args1= b, args2= c. Correct Answer: C 17 of 60 Question: 18Given the following code:public class Testlong a = new long10;public static void main ( String arg ) System.out.println (

20、a6 );Which statement is true?A. Output is null.B. Output is 0.C. When compile, some error will occur.D. When running, some error will occur. Explanation: When an array is created the members of the array is initialized. In this case all the elements are initialized to be 0. Correct Answer: B 18 of 6

21、0 Question: 19Given the following fragment of code:boolean m = true;if ( m = false )System.out.println(False);elseSystem.out.println(True);What is the result of the execution?A. FalseB. TrueC. NoneD. An error will occur when running. Explanation: = is the assignment operator. = is the compare operat

22、or. In this question the value of false is assigned to the variable m. Correct Answer: A 19 of 60 Question: 20Given the following code:public class Testpublic static void main(String arg)int i = 5;do System.out.println(i); while (-i5)System.out.println(“finished”);What will be output after execution

23、?A. 5B. 4C. 6D. FinishedE. None Explanation: The expressions in the block of do/while loop will be executed at least once. If the condition of this loop is not met the loop will stop after once execution, otherwise, it will continue to loop until the condition is no met. Correct Answer: A,D 20 of 60

24、 Question: 21What will be output after execution of the following code:outer: for(int i=0;i3; i+)inner: for(int j=0;j10B. f != null | f.length()10C. f = null | f.length()10D. f != null | f.length()10 Explanation: The operator | perform short-circuit logical expressions. If the first subexpression is

25、 true the second subexpression is skipped, for the entire expression is true when the first subexpression is true. The operator | doesnt perform short-circuit logical expressions. Both of the two subexpressions are performed. Because the f is null the expression f.length() will cause an exception is

26、 thrown. Correct Answer: A,B,D 43 of 60 Question: 44Which of the following can be parts of the Java source file Calculation1.java?A. public class Calculation1/.B. import java.io.*;C. package myPackage;D. import java.awt.*;E. static class Arg/.F. class Calcu/.G. public class Calculation2/. Explanatio

27、n: The static can not be a modifier before the keyword class. A Java source file can have only one public class. Correct Answer: A,B,C,D,F 44 of 60 Question: 45Which one of the following containers must be added to another container?A. WindowB. FrameC. DialogD. Panel Explanation: The Window, Frame a

28、nd Dialog are free-standing windows. But the Panel is contained within another container, or inside a Web browsers window. Correct Answer: D 45 of 60 Question: 46Which of the following classes are layout managers in Java?A. CardLayoutB. BorderLayoutC. PanelLayoutD. GridLayoutE. BagLayout Explanation

29、: There are five layout managers in Java. They are FlowLayout, BorderLayout, CardLayout, GridLayout and GridBaglayout. Correct Answer: A,B,D 46 of 60 Question: 47A Button is positioned in a Frame. Only height of the Button is affected by the Frame while the width is not. Which layout manager should

30、be used?A. FlowLayoutB. CardLayoutC. North and South of BorderLayoutD. East and West of BorderLayoutE. GridLayout Explanation: In the East and West of BorderLayout only the height of the component is affected when the Frame is resized. Correct Answer: D 47 of 60 Question: 48A Button is positioned in

31、 a Frame. Its size is not affected when the Frame is resized. Which layout manager should be used?A. FlowLayoutB. CardLayoutC. North and South of BorderLayoutD. East and West of BorderLayoutE. GridLayout Explanation: The size of the components is not constrained by the FlowLayout manager. When the a

32、rea is resized the size of these components is not changed. Correct Answer: A 48 of 60 Question: 49Which methods can get the event source in the WindowEvent?A. getFrame()B. getID()C. getSource()D. getWindow() Explanation: The methods getSource() and getWindow() can be used to get the event sources o

33、f the window events. Correct Answer: C,D 49 of 60 Question: 50Which statements of the event listener are true?A. Multiple listeners can be attached to one component.B. Only one listener can be attached to one component.C. One listener can receive and process the events from multiple components.D. On

34、e listener can receive and process the events from only one component. Explanation: One component can registers one or more listeners. One listener can be registered by multiple components. After being registered the listener can receive and process the events from these components. Correct Answer:

35、A,C 50 of 60 Question: 51What is the return value of the method in the event listener interface?A. intB. StringC. voidD. ObjectE. AWTEvent Explanation: All the methods in the event listener interfaces return void. Correct Answer: C 51 of 60 Question: 52Which of the following event listeners have eve

36、nt adapters defined in Java?A. MouseListenerB. KeyListenerC. ActionListenerD. ItemListenerE. WindowListener Explanation: Four listeners dont have their corresponding event adapters. They are ActionListener, ItemListener, AdjustmentListener and TextListener. Correct Answer: A,B,E 52 of 60 Question: 5

37、3Which one of the following methods is not related to the display of the applets?A. update()B. draw()C. repaint()D. paint() Explanation: The paint(), update() and repaint() are predefined methods in Java. They are related to the display of the applets. Correct Answer: B 53 of 60 Question: 54Given th

38、e following definition:TextArea ta = new TextArea (Hello, 5, 5);Which statements are true?A. The maximum number of characters in a line is 5.B. The displayed height is 5 lines otherwise constrain.C. The displayed string can use multiple fonts.D. The displayed strings are editable. Explanation: The T

39、extArea is constructed to a 5 row * 5 character text area. It cannot display multiple fonts. The strings are editable by default. The displayed width of a line is 5 characters, but the maximum number in a line is more than 5. Correct Answer: B,D 54 of 60 Question: 55Which method can be used to add M

40、enuBar to a Frame?A. setMenu()B. setMenuBar()C. add()D. addMenuBar() Explanation: MenuBar is added to a Frame by using the setMenuBar() method. The add() method is used to add components to containers. Correct Answer: B 55 of 60 Question: 56Which are not containers in Java?A. ScrollPaneB. CanvasC. ScrollbarD. AppletE. Dialog Explanation: Scrollbar and Canvas are not containers. The following classes are containers in Java: Panel, Window, ScrollPane, Dialog, Frame, Applet. Correct Answer: B,C 56 of 60 Question: 57Which of the following method

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论