1、Java结业测试题考试时间:180分钟 姓名:_选择题: (每题1 分, 共50分)1. Given the following code:class Test private 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 public int mC. change pr
2、ivate int m to static int mD. change private int m to int m2. Which methods are correct overloading 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).3. Given the following f
3、ragment of code: public class Base int w, x, y ,z; public Base(int a,int b) x=a; y=b; public Base(int a, int b, int c, int d) / assignment x=a, y=b w=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);4. Given the following d
4、efinition: 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();5. What is the return value of the main() method in Java?A. StringB. intC. charD. void6. Which are the valid identifiers in Java?A. fieldnameB. s
5、uperC. 3numberD. #numberE. $number7. Which are valid Java keywords?A. constB. NULLC. falseD. thisE. native8. Which are valid integral expressions in Java?A. 22B. 0x22C. 022D. 22H9. Given the following fragment of code, what are results of i and j after execution?int i = 1;int j;j = i+;A. 1, 1B. 1, 2
6、C. 2, 1D. 2, 210. Which of the following statements are true?A. is the arithmetic right shift operator.B. is the logical right shift operator.C. is the arithmetic right shift operator.D. is the logical right shift operator.11. Which of the following assignments are legal?A. float a = 2.0B. double b
7、= 2.0C. int c = 2D. long d = 212. Which one of the following arguments is the correct argument of the main() method?A. char argsB. char argsC. String argD. String args13. Which one of the following is correct to create an array?A. float f = new float66;B. float f = new float66;C. float f = new float
8、6;D. float f = new float66;E. float f = new float6;14. Given 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. m.length+115. Given the following command to run a correc
9、t class: java MyTest a b cWhich statements are true?A. args0 = MyTest a b cB. args0 = MyTestC. args0 = aD. args1= b16. Given the following code: public class Test static long a = new long10; public static void main ( String arg ) System.out.println ( a6 ); Which statement is true?A. Output is null.B
10、. Output is 0.C. When compile, some error will occur.D. When running, some error will occur.17. Given the following fragment of code:boolean m = true;if ( m = false ) System.out.println(False);else System.out.println(True); What is the result of the execution?A. FalseB. TrueC. NoneD. An error will o
11、ccur when running.18. Given the following code:public class Test public 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?A. 5B. 4C. 6D. FinishedE. None19. What will be output after execution of the foll
12、owing code: outer: for(int i=0;i3; i+) inner: for(int j=0;j2;j+) if(j=1) continue outer; System.out.println(j+ + “and” + +i); A. 0 and 0B. 0 and 1C. 0 and 2D. 1 and 0E. 1 and 1F. 1 and 2G. 2 and 0H. 2 and 1I. 2 and 220. Given the following code: switch (m) case 0: System.out.println(Condition 0); ca
13、se 1: System.out.println(Condition 1); case 2: System.out.println(Condition 2); case 3: System.out.println(Condition 3);break; default: System.out.println(Other Condition); Which values of m will cause Condition 2 is output?A. 0B. 1C. 2D. 3E. 4F. None21. Which modifiers are legal in Java?A. privateB
14、. publicC. protectedD. protectE. friend22. If a member variable of a class can be accessible only by the same package, which modifier should be used?A. privateB. publicC. protectedD. no modifierE. final23. Which modifier should be used to define a constant member variable?A. staticB. finalC. abstrac
15、tD. No modifier can be used24. Given the following definition of a class:public class Test private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg) Test t = new Test(); / some code. Which of the following usage are legal?A. t.fB. this.nC. Test.mD. Test.n25. Given the f
16、ollowing code:1) class Example2) String str;3) public Example()4) str= example;5) 6) public Example(String s)7) str=s;8) 9) 10) class Demo extends Example11) 12) public class Test13) public void f () 14) Example ex = new Example(Good);15) Demo d = new Demo(Good);16) Which line will cause an error?A.
17、 line 3B. line 6C. line 10D. line 14E. line 1526. Given the following class definition in one source file:class Base public Base () /. public Base ( int m ) /. protected void fun( int n ) /. public class Child extends Base / member methodsWhich methods can be added into the Child class correctly?A.
18、private void fun( int n ) /.B. void fun ( int n ) /. C. protected void fun ( int n ) /. D. public void fun ( int n ) /. E. public m() /. 27. Which statements are correct?A. In Java single inheritance is allowed, which makes code more reliable.B. A subclass inherits all methods ( including the constr
19、uctor ) from the superclass.C. A class can implement as many interfaces as needed.D. When a class implements an interface, it can define as many methods of the interface as needed.28. In the Test.java source file, which are correct class definitions?A. public class test public int x = 0; public test
20、(int x) this.x = x; B. public class Test public int x=0; public Test(int x) this.x = x; C. public class Test extends T1, T2 public int x = 0; public Test (int x) this.x = x; D. public class Test extends T1 public int x=0; public Test(int x) this.x = x; E. protected class Test extends T2 public int x
21、=0; public Test(int x) this.x=x; 29. The Person, Student and Teacher are class names. These classes have the following inheritance relation as shown below: Person | - | | Student TeacherThere is the following expression in a Java source file: Person p = new Student();Which one of the following state
22、ments are true?A. The expression is legal.B. The expression is illegal.C. Some errors will occur when compile.D. Compile is correct but it will be wrong when running.30. The Person, Student and Teacher are class names. These classes have the following inheritance relation as shown below: Person | -
23、| | Student Teacher In Java source file a specific method has an argument. In order to handle all these classes in this method which type of argument of this method should be used?A. PersonB. StudentC. TeacherD. ObjectE. None of them can be used.31. .The Person, Student and Teacher are class names.
24、These classes have the following inheritance relation as shown below: Person | - | | Student Teacher There is the following expression in a Java source file: Person p = new Teacher(); Which of the following expressions return true?A. p instanceof TeacherB. p instanceof StudentC. p instanceof PersonD
25、. None of them returns true32. Given the following code:public class Test public static void main(String args) String str=new String(World); char ch=H,e,l,l,o; change(str,ch); System.out.println(str + and + ch); public static void change(String str, char ch) str=Changed; ch0=C; What is the result af
26、ter execution?A. World and HelloB. World and CelloC. Changed and HelloD. Changed and CelloE. none of above33. Given the following fragment of code: Double d1 = new Double(1.0); Double d2 = new Double(1.0); Float f = new Float(1.0F);Which results of the following expressions are true?A. d1 = d2B. d1.
27、equals(d2)C. d1 = fD. f.equals(d1)34. Given the following code:public void fun () int i; try i=System.in.read (); System.out.println(Location 1); catch (IOException e) System.out.println(Location 2); finally System.out.println(Location 3); System.out.println(Location 4); If an IOException occurs, wh
28、at will be printed?A. Location 1B. Location 2C. Location 3D. Location 435. If the method func() is allowed to throw out the IOException, which declaration of this method can used?A. public int func(int i)B. public int func(int i) throw IOExceptionC. public int func(int i) throw ExceptionD. public in
29、t func(int i) throws IOExceptionE. public int func(int i) throws Exception36. Consider the following class:1. class Test 2. void test(int i) 3. System.out.println(I am an int.);4. 5. void test(String s) 6. System.out.println(I am a string.);7. 8.9. public static void main(String args) 10. Test t=new
30、 Test();11. char ch=y;12. t.test(ch);13. 14. Which of the statements below is true?(Choose one.)A. Line 5 will not compile, because void methods cannot be overridden.B. Line 12 will not compile, because there is no version of test() that rakes a char argument.C. The code will compile but will throw
31、an exception at line 12.D. The code will compile and produce the following output: I am an int.E. The code will compile and produce the following output: I am a String.37. Which of the following fragments might cause errors?A. String s = Gone with the wind; String t = good ; String k = s + t;B. Stri
32、ng s = Gone with the wind; String t; t = s3 + one;C. String s = Gone with the wind; String standard = s.toUpperCase();D. String s = home directory; String t = s - directory.38. Which of the following answer is correct to express the value 8 in octal number?A. 010B. 0x10C. 08D. 0x839. Which of the fo
33、llowing assignment is not correct?A. float f = 11.1;B. double d = 5.3E12;C. double d = 3.14159;D. double d = 3.14D.40. Which of the following statements about variables and their scopes are true?A. Instance variables are member variables of a class.B. Instance variables are declared with the static
34、keyword.C. Local variables defined inside a method are created when the method is executed.D. Local variables must be initialized before they are used.41. Which of the following statements about declaration are true?A. Declaration of primitive types such as boolean, byte and so on does not allocate
35、memory space for the variable.B. Declaration of primitive types such as boolean, byte and so on allocates memory space for the variable.C. Declaration of nonprimitive types such as String, Vector and so on does not allocate memory space for the object.D. Declaration of nonprimitive types such as Str
36、ing, Vector ans so on allocates memory space for the object.42. Which fragments are correct in Java source file?A. package testpackage;public class Test/do something.B. import java.io.*;package testpackage;public class Test/ do something.C. import java.io.*;class Person/ do something.public class Te
37、st/ do something.D. import java.io.*;import java.awt.*;public class Test/ do something.43. class Parent String one, two; public Parent(String a, String b) one = a; two = b; public void print() System.out.println(one); public class Child extends Parent public Child(String a, String b) super(a,b); pub
38、lic void print() System.out.println(one + to + two); public static void main(String arg) Parent p = new Parent(south, north); Parent t = new Child(east, west); p.print(); t.print(); Which of the following is correct?A. Cause error during compilation.B. south eastC. south to north east to westD. sout
39、h to north eastE. south east to west44. Given the uncompleted method:1)2) success = connect();3) if (success=-1) 4) throw new TimedOutException();5) 6)TimedOutException is not a RuntimeException. Which can complete the method of declaration when added at line 1?A. public void method()B. public void method() throws ExceptionC. public void method() throws TimedOutExceptio