1.Which of the following range of short is correct?
-128 -- 127
-32768 -- 32767
-215 -- 215-1
-231 -- 231-1
2、Which declarations of identifiers are legal?
A. $persons
B. TwoUsers
C. *point
D. this
E. _endline
3、Which statement of assigning a long type variable to a hexadecimal value is correct?
A. long number = 345L;
B. long number = 0345;
C. long number = 0345L;
D. long number = 0x345L.
4、Which of the following fragments might cause errors?
A. String s = "Gone with the wind";
String t = " good ";
String k = s + t;
B. String s = "Gone with the wind";
String t;
t = s[3] + "one";
C. String s = "Gone with the wind";
String standard = s.toUpperCase();
D. String s = "home directory";
String t = s - "directory".
5、class Person {
private int a;
public int change(int m){ return m; }
}
public class Teacher extends Person {
public int b;
public static void main(String arg[]){
Person p = new Person();
Teacher t = new Teacher();
int i;
// point x
}
}
Which are syntactically valid statement at// point x?
A. i = m;
B. i = b;
C. i = p.a;
D. i = p.change(30);
E. i = t.b.
6、Which layout manager is used when the frame is resized the buttons's position in the Frame might be changed?
A. BorderLayout
B. FlowLayout
C. CardLayout
D. GridLayout
7、Given the following code fragment:
1) public void create() {
2) Vector myVect;
3) myVect = new Vector();
4) }
Which of the following statements are true?
A. The declaration on line 2 does not allocate memory space for the variable myVect.
B. The declaration on line 2 allocates memory space for a reference to a Vector object.
C. The statement on line 2 creates an object of class Vector.
D. The statement on line 3 creates an object of class Vector.
E. The statement on line 3 allocates memory space for an object of class Vector
8、Which of the following answer is correct to express the value 8 in octal (八进制)number?
A. 010
B. 0x10
C. 08
D. 0x8
9、Which are not Java keywords?
A. TRUE
B. sizeof
C. const
D. super
E. void
10、Which of the following statements are true?
A. The equals() method determines if reference values refer to the same object.
B. The == operator determines if the contents and type of two separate objects match.
C. The equals() method returns true only when the contents of two objects match.
D. The class File overrides equals() to return true if the contents and type of two separate objects match.
11、Which statements about inheritance are true?
A. In Java programming language only allows single inheritance.
B. In Java programming language allows a class to implement only one interface.
C. In Java programming language a class cannot extend a class and implement a interface together.
D. In Java programming language single inheritance makes code more reliable.
12、
1) class Person {
2) public void printValue(int i, int j) {/*…*/ }
3) public void printValue(int i){/*...*/ }
4) }
5) public class Teacher extends Person {
6) public void printValue() {/*...*/ }
7) public void printValue(int i) {/*...*/}
8) public static void main(String args[]){
9) Person t = new Teacher();
10) t.printValue(10);
11) }
12) }
Which method will the statement on line 10 call?
A. on line 2
B. on line 3
C. on line 6
D. on line 7
(d)
13、Which are not Java primitive types?
A. short
B. Boolean
C. unit
D. float
14 Which keyword should be used to enable interaction with the lock of an object? The flag allows exclusive access to that object.
A. transient
B. synchronized
C. serialize
D. static
(b)
15、Which is the return type of the method main()?
A. int
B. void
C. boolean
D. static
16、Given the following code:
if (x>0) { System.out.println("first"); }
else if (x>-3) { System.out.println("second"); }
else { System.out.println("third"); }
Which range of x value would print the string "second"?
A. x > 0
B. x > -3
C. x <= -3
D. x <= 0 & x > -3
17、Given the following expression about TextField which use a proportional pitch font.
TextField t = new TextField("they are good",40);
Which statement is true?
A. The displayed string can use multiple fonts.
B. The maximum number of characters in a line will be 40.
C. The displayed width is exactly 40 characters.
D. The user can edit the characters.
18、Which statements about the garbage collection are true?
A. The program developer must create a thread to be responsible for free the memory.
B. The garbage collection will check for and free memory no longer needed.
C. The garbage collection allow the program developer to explicity and immediately free the memory.
D. The garbage collection can free the memory used java object at expect time.
-128 -- 127
-32768 -- 32767
-215 -- 215-1
-231 -- 231-1
2、Which declarations of identifiers are legal?
A. $persons
B. TwoUsers
C. *point
D. this
E. _endline
3、Which statement of assigning a long type variable to a hexadecimal value is correct?
A. long number = 345L;
B. long number = 0345;
C. long number = 0345L;
D. long number = 0x345L.
4、Which of the following fragments might cause errors?
A. String s = "Gone with the wind";
String t = " good ";
String k = s + t;
B. String s = "Gone with the wind";
String t;
t = s[3] + "one";
C. String s = "Gone with the wind";
String standard = s.toUpperCase();
D. String s = "home directory";
String t = s - "directory".
5、class Person {
private int a;
public int change(int m){ return m; }
}
public class Teacher extends Person {
public int b;
public static void main(String arg[]){
Person p = new Person();
Teacher t = new Teacher();
int i;
// point x
}
}
Which are syntactically valid statement at// point x?
A. i = m;
B. i = b;
C. i = p.a;
D. i = p.change(30);
E. i = t.b.
6、Which layout manager is used when the frame is resized the buttons's position in the Frame might be changed?
A. BorderLayout
B. FlowLayout
C. CardLayout
D. GridLayout
7、Given the following code fragment:
1) public void create() {
2) Vector myVect;
3) myVect = new Vector();
4) }
Which of the following statements are true?
A. The declaration on line 2 does not allocate memory space for the variable myVect.
B. The declaration on line 2 allocates memory space for a reference to a Vector object.
C. The statement on line 2 creates an object of class Vector.
D. The statement on line 3 creates an object of class Vector.
E. The statement on line 3 allocates memory space for an object of class Vector
8、Which of the following answer is correct to express the value 8 in octal (八进制)number?
A. 010
B. 0x10
C. 08
D. 0x8
9、Which are not Java keywords?
A. TRUE
B. sizeof
C. const
D. super
E. void
10、Which of the following statements are true?
A. The equals() method determines if reference values refer to the same object.
B. The == operator determines if the contents and type of two separate objects match.
C. The equals() method returns true only when the contents of two objects match.
D. The class File overrides equals() to return true if the contents and type of two separate objects match.
11、Which statements about inheritance are true?
A. In Java programming language only allows single inheritance.
B. In Java programming language allows a class to implement only one interface.
C. In Java programming language a class cannot extend a class and implement a interface together.
D. In Java programming language single inheritance makes code more reliable.
12、
1) class Person {
2) public void printValue(int i, int j) {/*…*/ }
3) public void printValue(int i){/*...*/ }
4) }
5) public class Teacher extends Person {
6) public void printValue() {/*...*/ }
7) public void printValue(int i) {/*...*/}
8) public static void main(String args[]){
9) Person t = new Teacher();
10) t.printValue(10);
11) }
12) }
Which method will the statement on line 10 call?
A. on line 2
B. on line 3
C. on line 6
D. on line 7
(d)
13、Which are not Java primitive types?
A. short
B. Boolean
C. unit
D. float
14 Which keyword should be used to enable interaction with the lock of an object? The flag allows exclusive access to that object.
A. transient
B. synchronized
C. serialize
D. static
(b)
15、Which is the return type of the method main()?
A. int
B. void
C. boolean
D. static
16、Given the following code:
if (x>0) { System.out.println("first"); }
else if (x>-3) { System.out.println("second"); }
else { System.out.println("third"); }
Which range of x value would print the string "second"?
A. x > 0
B. x > -3
C. x <= -3
D. x <= 0 & x > -3
17、Given the following expression about TextField which use a proportional pitch font.
TextField t = new TextField("they are good",40);
Which statement is true?
A. The displayed string can use multiple fonts.
B. The maximum number of characters in a line will be 40.
C. The displayed width is exactly 40 characters.
D. The user can edit the characters.
18、Which statements about the garbage collection are true?
A. The program developer must create a thread to be responsible for free the memory.
B. The garbage collection will check for and free memory no longer needed.
C. The garbage collection allow the program developer to explicity and immediately free the memory.
D. The garbage collection can free the memory used java object at expect time.
19 Which of the following are valid constructors of the class java.lang.AssertionError?
A. AssertionError()
B. AssertionError(String detailMessage)
C. AssertionError(boolean detailMessage)
D. AssertionError(int detailMessage)
E. AssertionError(StackTraceElement detailMessage)
20 What should be inserted at line 7 so that the code compiles and guarantees to print -
Apple Cricket Banana in the same order.
1. import java.util.*;
2.
3. public class SetTest
4. {
5. public static void main(String args[])
6. {
7. // what should be inserted here?
8.
9. set.add("Apple");
10. set.add("Cricket");
11. set.add("Banana");
12.
13. Iterator iter = set.iterator();
14. while(iter.hasNext())
15. {
16. System.out.print(iter.next() + " ");
17. }
18. }
19. }
A. Set set = new LinkedHashSet();
B. Set set = new HashSet();
C. Set set = new TreeSet();
D. TreeSet maintains the Set elements sorted according to their natural order; however other sets
21 What will be the result of executing the following main() method?
1. public static void main(String[] args)
2. {
3. String myString;
4. int x = 100;
5.
6. if (x < 100) myString = "x is less than 100";
7. if (x > 100) myString = "x is greater than 100";
8. System.out.println(myString.length());
9. }
A. The code will compile with a warning that variable myString might not have been initialized
B. The code will compile without any warnings
C. The code will not compile. But it will compile and print the length of myString if the variable myString is initialized in an unconditional statement before line 8
D. None of these
22 What results from running the code below?
int a = -5; int b = -2;
System.out.println(a % b);
A. 0
B. 1
C. -1
D. A compiler error saying "%" operator is not valid for negative numbers.
23 What is the return type of method add(Object o) of Set interface, and what does it indicate?
A. It returns an int representing hash code of the newly added object
B. It returns an Integer object representing hash code of the newly added object
C. It returns a boolean. Returns true if this set already contains the specified element.
D. It returns a boolean. Returns true if this set did not already contain the specified element.
E. Return type is void. Any error in the add operation is reported by throwing an exception.
F. None of these
23 Which of the following classes implement java.util.Map interface?
A. Hashtable
B. HashMap
C. Dictionary
D. Vector
24 What is the valid declaration for the finalize() method?
A. protected void finalize() throws Throwable
B. final finalize()
C. public final finalize()
D. private boolean finalize()
E. private final void finalize() throws Exception
25 Which one of the following fragments shows the most appropriate way to throw an exception? Assume that any undeclared variables have been appropriately declared elsewhere and are in scope and have meaningful values.
A. 1. Exception e = new MalformedURLException("Invalid URL");
2. if (!myURL.isValid()) // myURL is a URL object
3. {
4. throw e;
5. }
B. 1. if (!myURL.isValid ())
2. {
3. throw new MalformedURLException("URL " + myURL.getName() + " is not valid");
4. }
C. 1. if (!myURL.isValid ())
2. {
3. throw IOException;
4. }
D. 1. if (!myURL.isValid ())
2. {
3. throw "Invalid URL";
4. }
E. 1. if (!myURL.isValid ())
2. {
3. throw new IOException();
4. }
26 What will happen when you attempt to compile and run the following code?
(Assume that the code is compiled and run with assertions enabled.)
public class AssertTest {
private void methodA(int i) {
assert i >= 0 : methodB();
System.out.println(i);
}
private String methodB(){
return "The value must not be negative";
}
public static void main(String args[]){
AssertTest test = new AssertTest();
test.methodA(-10);
}
}
A. It will print -10.
B. It will result in AssertionError with the message -"The value must not be negative".
C. The code will not compile.
D. None of these
26 Which Java collection class can be used to maintain the entries in the order in which they were last accessed?
A. java.util.HashSet
B. java.util.LinkedHashMap
C. java.util.Hashtable
D. java.util.Vector
E. None of these
27 What will happen when you attempt to compile and run the following code?
class MyClass {
static String myName = "SCJP";
MyClass getMyClass() {
System.out.println(myName);
return null;
}
public static void main(String[ ] args) {
System.out.println( new MyClass().getMyClass().myName );
}
}
A. Compile time error
B. Run time error
C. Prints SCJP twice
D. Prints SCJP once
E. None of the above
28 A block of text contains 100 words. You are required to make a list of distinct words from those 100 words;moreover you are required to report how many distinct words exist in that block of text. Which Java collection class would you use;and which of its method would give the number of distinct words in the block?
A. java.util.LinkedList class, and its size() method
B. java.util.HashSet class, and its size() method
C. java.util.HashMap class, and its size() method
D. java.util.ArrayList class, and its size() method
E. java.util.Dictionary class, and its size() method
29 What will be printed by the following code?
String banner = "One man, One vote";
int subInd1 = banner.lastIndexOf("One", 10);
System.out.println(subInd1);
A. 0
B. -1
C. 10
D. None of these
30 What results by running the following code fragment?
int a = 8;
int b = 3;
float f = a++/b--;
System.out.println(f);
A. 3.0
B. 4.5
C. 2.0
D. 2.6
A. AssertionError()
B. AssertionError(String detailMessage)
C. AssertionError(boolean detailMessage)
D. AssertionError(int detailMessage)
E. AssertionError(StackTraceElement detailMessage)
20 What should be inserted at line 7 so that the code compiles and guarantees to print -
Apple Cricket Banana in the same order.
1. import java.util.*;
2.
3. public class SetTest
4. {
5. public static void main(String args[])
6. {
7. // what should be inserted here?
8.
9. set.add("Apple");
10. set.add("Cricket");
11. set.add("Banana");
12.
13. Iterator iter = set.iterator();
14. while(iter.hasNext())
15. {
16. System.out.print(iter.next() + " ");
17. }
18. }
19. }
A. Set set = new LinkedHashSet();
B. Set set = new HashSet();
C. Set set = new TreeSet();
D. TreeSet maintains the Set elements sorted according to their natural order; however other sets
21 What will be the result of executing the following main() method?
1. public static void main(String[] args)
2. {
3. String myString;
4. int x = 100;
5.
6. if (x < 100) myString = "x is less than 100";
7. if (x > 100) myString = "x is greater than 100";
8. System.out.println(myString.length());
9. }
A. The code will compile with a warning that variable myString might not have been initialized
B. The code will compile without any warnings
C. The code will not compile. But it will compile and print the length of myString if the variable myString is initialized in an unconditional statement before line 8
D. None of these
22 What results from running the code below?
int a = -5; int b = -2;
System.out.println(a % b);
A. 0
B. 1
C. -1
D. A compiler error saying "%" operator is not valid for negative numbers.
23 What is the return type of method add(Object o) of Set interface, and what does it indicate?
A. It returns an int representing hash code of the newly added object
B. It returns an Integer object representing hash code of the newly added object
C. It returns a boolean. Returns true if this set already contains the specified element.
D. It returns a boolean. Returns true if this set did not already contain the specified element.
E. Return type is void. Any error in the add operation is reported by throwing an exception.
F. None of these
23 Which of the following classes implement java.util.Map interface?
A. Hashtable
B. HashMap
C. Dictionary
D. Vector
24 What is the valid declaration for the finalize() method?
A. protected void finalize() throws Throwable
B. final finalize()
C. public final finalize()
D. private boolean finalize()
E. private final void finalize() throws Exception
25 Which one of the following fragments shows the most appropriate way to throw an exception? Assume that any undeclared variables have been appropriately declared elsewhere and are in scope and have meaningful values.
A. 1. Exception e = new MalformedURLException("Invalid URL");
2. if (!myURL.isValid()) // myURL is a URL object
3. {
4. throw e;
5. }
B. 1. if (!myURL.isValid ())
2. {
3. throw new MalformedURLException("URL " + myURL.getName() + " is not valid");
4. }
C. 1. if (!myURL.isValid ())
2. {
3. throw IOException;
4. }
D. 1. if (!myURL.isValid ())
2. {
3. throw "Invalid URL";
4. }
E. 1. if (!myURL.isValid ())
2. {
3. throw new IOException();
4. }
26 What will happen when you attempt to compile and run the following code?
(Assume that the code is compiled and run with assertions enabled.)
public class AssertTest {
private void methodA(int i) {
assert i >= 0 : methodB();
System.out.println(i);
}
private String methodB(){
return "The value must not be negative";
}
public static void main(String args[]){
AssertTest test = new AssertTest();
test.methodA(-10);
}
}
A. It will print -10.
B. It will result in AssertionError with the message -"The value must not be negative".
C. The code will not compile.
D. None of these
26 Which Java collection class can be used to maintain the entries in the order in which they were last accessed?
A. java.util.HashSet
B. java.util.LinkedHashMap
C. java.util.Hashtable
D. java.util.Vector
E. None of these
27 What will happen when you attempt to compile and run the following code?
class MyClass {
static String myName = "SCJP";
MyClass getMyClass() {
System.out.println(myName);
return null;
}
public static void main(String[ ] args) {
System.out.println( new MyClass().getMyClass().myName );
}
}
A. Compile time error
B. Run time error
C. Prints SCJP twice
D. Prints SCJP once
E. None of the above
28 A block of text contains 100 words. You are required to make a list of distinct words from those 100 words;moreover you are required to report how many distinct words exist in that block of text. Which Java collection class would you use;and which of its method would give the number of distinct words in the block?
A. java.util.LinkedList class, and its size() method
B. java.util.HashSet class, and its size() method
C. java.util.HashMap class, and its size() method
D. java.util.ArrayList class, and its size() method
E. java.util.Dictionary class, and its size() method
29 What will be printed by the following code?
String banner = "One man, One vote";
int subInd1 = banner.lastIndexOf("One", 10);
System.out.println(subInd1);
A. 0
B. -1
C. 10
D. None of these
30 What results by running the following code fragment?
int a = 8;
int b = 3;
float f = a++/b--;
System.out.println(f);
A. 3.0
B. 4.5
C. 2.0
D. 2.6
1042

被折叠的 条评论
为什么被折叠?



