紅色答案為參考答案
1、從下列選項中選擇正確的Java表達式(多選)
A. int k=new String(“aa”); B. String str=String(“bb”);
C. char c=74; D. long j=8888;
2、下面那幾個函數是public void method(){...}的重載函數?
A public void method( int m){...} B public int method(){...}
C public void method2(){...} D public int method(int m,float f ){...}
3、Which two demonstrate a "has a" relationship(Choose two)?
A. public interface Person { }
public class Employee extends Person{ }
B. public interface Shape { }
public interface Rectandle extends Shape { }
C. public interface Colorable { }
public class Shape implements Colorable { }
D. public class Species{ }
public class Animal{private Species species;}
E. interface Component{ }
class Container implements Component{
private Component[] children;
}
解析:"Is-a”代表類之間或類與接口的繼承關系,比如貓是動物,狗也是動物,都繼承了動物的共同特性,再用OO語言實現時,應將貓和狗定義成兩種類,均繼承動物類。"Has-a"代表的是對象和他成員的從屬關系,同一種類的對象,通過它們的屬性的不同值來區別。
4、已知表達式 int m [ ] = {0,1,2,3,4,5,6}; 下面哪個表達式的值與數組下標量總數相等?
A m.length() B m.length C m.length()+1 D m.length-1
5、方法resume()負責恢復哪些線程的執行
A 通過調用stop()方法而停止的線程。 B 通過調用sleep()方法而停止的線程。
C 通過調用wait()方法而停止的線程。 D 通過調用suspend()方法而停止的線程。
6、請看如下代碼
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
}
}
7、 下面哪些放在// point x?行是正確的?
A i = m; B i = b;
C i = p.a; D i = p.change(30);
E i = t.b;
8、關於運算符>>和>>>描述正確的是
A. >>執行移動 B. >>執行翻轉
C. >>執行有符號右移,>>>執行無符號右移 D. >>執行無符號右移,>>>執行有符號右移
9、下列關於棧的敘述正確的是
A棧是非線性結構 B棧是一種樹狀結構
C棧具有先進先出的特征 D棧具有后進先出的特征
10、選出Java語言中的關鍵詞(多選)
A. NULL B. sizeof C. implements D. extends
11、字符(char)的整型表示范圍為
- 0 . . . 32767 C. -256 . . . 255
- 0 . . . 65535 D. -32768 . . . 32767
12、下述代碼的執行結果是
class Super {
public int getLength() {return 4;}
}
public class Sub extends Super {
public long getLength() {return 5;}
public static void main (String[]args) {
Super sooper = new Super ();
Super sub = new Sub();
System.out.println(sooper.getLength()+ “,” + sub.getLength() );
}
}
A. 4, 4 B. 4, 5 C. 5, 4 D. 5, 5 E. 代碼不能被編譯
13、關於Java語言,下列描述正確的是(多選)
A. switch 不能夠作用在String類型上 B. List, Set, Map都繼承自Collection接口
C. Java語言支持goto語句 D. GC是垃圾收集器,程序員不用擔心內存管理
14、指出下列程序運行的結果
public class Example{
String str=new String("good");
char[]ch={'a','b','c'};
public static void main(String args[]){
Example ex=new Example();
ex.change(ex.str,ex.ch);
ex.str;
System.out.print(ex.str+" and ");
System.out.print(ex.ch);
}
public void change(String str,char ch[]){
str="test ok";
ch[0]='g';
}
}
A good and abc B good and gbc C test ok and abc D test ok and gbc
15、寫出下面代碼的執行結果 引用
public class MyClass {
static void aMethod(StringBuffer sf1, StringBuffer sf2) {
sf1.append(sf2);
sf2 = sf1;
}
public static void main(String[] args){
StringBuffer sf1 = new StringBuffer("A");
StringBuffer sf2 = new StringBuffer("B");
aMethod(sf1,sf2);
System.out .println(sf1+ "":"+sf2);
}
}
答:AB:B
16、關於異常(Exception),下列描述正確的是(多選)
A. 異常的基類為Exception,所有異常都必須直接或者間接繼承它
B. 異常可以用try{ . . .}catch(Exception e){ . . .}來捕獲並進行處理
C. 如果某異常繼承RuntimeException,則該異常可以不被聲明
D. 異常可以隨便處理,而不是拋給外層的程序進行處理
17、(單選)聲明一個委托public int myCallBack(int x); 則用該委托產生的回調方法的原型應該是
A. void myCallBack(int x) B. int receive(int num)
C. String receive(int x) D. 不確定的
18、(單選)下面的代碼實現了設計模式中的什么模式
public class A {
private A instance;
private A() {
}
public static A getInstance {
if ( A == null )
instance = new A();
return instance;
}
}
A. Factory B. Abstract Factory C. Singleton D. Builder
19、三種字符串判空串方法:
1: bool isEmpty = (str.Length == 0);
2: bool isEmpty = (str == String.Empty);
3: bool isEmpty = (str == "");
哪種方法正確?
A. 1 B. 2 C. 3
20、下面正確的是
A)float f = 3.14; //不帶f默認為double類型 B)byte i = 225; //默認為int類型
C)log k = 33; D)int p[ ][ ];