应届生Java笔试题

匿名网友 匿名网友 发布于: 2015-08-30 00:00:00
阅读 139 收藏 0 点赞 0 评论 0

JAVA基础测试题

班级                 姓名              分数         

一、选择题:

1、下面哪些是short型的取值范围(    )

A. -27 — 27-1  B. 0 – 216-1    C. 215 – 215-1  D. 231 – 231-1

2、下面哪些是合法的标识符(    )

A. $persons    B. TwoUsers C. *point       D. This    E. _endline

3、哪些是将一个十六进制值赋值给一个long型变量(    )

A. long number = 345L;              B. long number = 0345;
C. long number = 0345L;      D. long number = 0x345L

4、下面的哪些程序片断可能导致错误(    )

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、在// point x处的哪些申明是句法上合法的(    )

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
}
}

A. i = m; B. i = b;  C. i = p.a;              D. i = p.change(30);      E. i = t.b.

6、当Frame的大小被改变时Frame中的按钮的位置可能被改变时使用的哪一个布局管理器(    )

A. BorderLayout    B. FlowLayout       C. CardLayout              D. GridLayout

7、给出下面的代码片断。。。下面的哪些陈述为true(    )

1) public void create() {
2} Vector myVect;
3} myVect = new Vector();
4} }
A. 第二行的声明不会为变量myVect分配内存空间。
B. 第二行的声明分配一个到Vector对象的引用的内存空间。
C. 第二行语句创建一个Vector类对象。
D. 第三行语句创建一个Vector类对象。
E. 第三行语句为一个Vector类对象分配内存空间。

8、哪些不是Java关键字(    )

A. TRUE        B. Sizeof        C. const          D. Super        E. void

9、下面的哪些叙述为真(    )

A. equals()方法判定引用值是否指向同一对象。
B. == 操作符判定两个分立的对象的内容和类型是否一致。
C. equals()方法只有在两个对象的内容一致时返回true。
D. 类File重写方法equals()在两个分立的对象的内容和类型一致时返回true。

10、下面关于继承的哪些叙述是正确的(    )

A.在java中只允许单一继承。
B.在java中一个类只能实现一个接口。
C.在java中一个类不能同时继承一个类和实现一个接口。
D.java的单一继承使代码更可靠。

11、第十行的声明可以调用哪些方法(    )

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} }

A. on line 2    B. on line 3    C. on line 6    D. on line 7

12、下面哪些不是java的原始数据类型(    )

A. Short  B. Boolean     C. Unint  D. float

13、使用”<<“和 “>>”操作符的哪些陈述是对的(    )

A. 0000 0100 0000 0000 0000 0000 0000 0000<<5 gives
1000 0000 0000 0000 0000 0000 0000 0000
B. 0000 0100 0000 0000 0000 0000 0000 0000<<5 gives
1111 1100 0000 0000 0000 0000 0000 0000
C. 1100 0000 0000 0000 0000 0000 0000 0000>>5 gives
1111 1110 0000 0000 0000 0000 0000 0000
D. 1100 0000 0000 0000 0000 0000 0000 0000>>5 gives
0000 0110 0000 0000 0000 0000 0000 0000

14、给出下面的代码,…,x的取值在什么范围内时将打印字符串”second”(    )

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

15、给出以下关于一个使用适当的字符间距的字体的TextField的表达式。(    )
…哪些叙述是对的

TextField t = new TextField(“they are good”,40);

A. 被显示的字符串可以使用多种字体。
B. 一行中最大的字符数是40
C. 显示的宽度正好是40个字符宽。
D. 用户可以编辑字符。

16、关于垃圾收集的哪些叙述是对的(           )

A. 程序开发者必须自己创建一个线程进行内存释放的工作。
B. 垃圾收集将检查并释放不再使用的内存。
C. 垃圾收集允许程序开发者明确指定并立即释放该内存。
D. 垃圾收集能够在期望的时间释放被java对象使用的内存。

17、给出下面的代码:… 在编译时哪行将导致一个错误(         )

1) public class Test {
2} int m, n;
3} public Test() {}
4} public Test(int a) { m=a; }
5} public static void main(String arg[]) {
6} Test t1,t2;
7} int j,k;
8} j=0; k=0;
9} t1=new Test();
10} t2=new Test(j,k);
11} }
12} }

A. line 3         B. line 5         C. line 6         D. line 10

18、方法resume()负责恢复哪些线程的执行(        )

A. 通过调用stop()方法而停止的线程。
B. 通过调用sleep()方法而停止运行的线程。
C. 通过调用wait()方法而停止运行的线程。
D. 通过调用suspend()方法而停止运行的线程。

19、有关线程的哪些叙述是对的(           )

A. 一旦一个线程被创建,它就立即开始运行。
B. 使用start()方法可以使一个线程成为可运行的,但是它不一定立即开始运行。
C. 当一个线程因为抢先机制而停止运行,它被放在可运行队列的前面。
D. 一个线程可能因为不同的原因停止(cease)并进入就绪状态。

20、给出下面的不完整的方法,下面的哪些声明可以被加入第一行完成此方法的声明:下面的哪些声明可以完成此方法的声明。TimedOutException 不是一个RuntimeException(  )

1)
2) { success = connect()
3} if (success==-1) {
4} throw new TimedOutException();
5} }
6}}

A. public void method()
B. public void method() throws Exception
C. public void method() throws TimedOutException
D. public void method() throw TimedOutException
E. public throw TimedOutException void method()

22、给出下面的不完整的类代码:下面的哪些表达式可以加到构造方法中的”doing the same as…”处?(           )

class Person {
String name, department;
int age;
public Person(String n){ name = n; }
public Person(String n, int a){ name = n; age = a; }
public Person(String n, String d, int a) {
// doing the same as two arguments version of constructor
// including assignment name=n,age=a
department = d;
}
}

A. Person(n,a);      B. this(Person(n,a));      C. this(n,a);    D. this(name,age).

23、在oneMethod()方法运行正常的情况下将显示什么?(         )

public void test() {
try { oneMethod();
System.out.println(“condition 1”);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(“condition 2”);
} catch(Exception e) {
System.out.println(“condition 3”);
} finally {
System.out.println(“finally”);
}
}

A. condition 1        B. condition 2        C. condition 3        D. Finally

24、给出下面的代码:输出将是什么(           )

public class Test {
void printValue(int m){
do { System.out.println(“The value is”+m);
}
while( –m > 10 )
}
public static void main(String arg[]) {
int i=10;
Test t= new Test();
t.printValue(i);
}
}
A. The value is 8   B. The value is 9    C. The value is 10  D. The value is 11

25、给出下面的代码:哪些行在编译时可能产生错误(              )

1) public void modify() {
2) int i, j, k;
3) i = 100;
4) while ( i > 0 ) {
5) j = i * 2;
6) System.out.println (” The value of j is ” + j );
7) k = k + 1;
8) i–;
9) }
10} }

A.line 4          B. line 6         C. line 7         D. line 8

26、给出下面的代码片断:…哪些行将导致错误(    )

1) String str = null;
2) if ((str != null) && (str.length() > 10)) {
3} System.out.println(“more than 10”);
4} }
5) else if ((str != null) & (str.length() < 5)) {
6} System.out.println(“less than 5”);
7} }
8) else { System.out.println(“end”); }

A. line 1         B. line 2         C. line 5         D. line 8

27、 给出下面的代码:… 哪些叙述是对的(    )

public class Person{
int arr[] = new int[10];
public static void main(String a[]) {
System.out.println(arr[1]);
}
}

A. 编译时出错。   B. 编译时正确而运行时出错。  C. 输出0。   D. 输出null

28、哪些方法可以加入类Child中(    )

public class Parent {
public int addValue( int a, int b) {
int s;
s = a+b;
return s;
}
}
class Child extends Parent {
}

A. int addValue( int a, int b ){// do something…}
B. public void addValue (){// do something…}
C. public int addValue( int a ){// do something…}
D. public int addValue( int a, int b )throws MyException {//do something…}

29、共有成员变量MAX_LENGTH是一个int型值,变量的值保持常数值100。使用一个短声明定义这个变量(             )

A. public int MAX_LENGTH=100;
B. final int MAX_LENGTH=100;
C. final public int MAX_LENGTH=100;
D. public final int MAX_LENGTH=100.

30、哪些返回true(           )

String s= “hello”;
String t = “hello”;
char c[] = {‘h’,’e’,’l’,’l’,’o’} ;
A. s.equals(t);        B. t.equals(c);        C. s==t;          D. t.equals(new String(“hello”));  E. t==c.

31、类Teacher和Student都是类Person的子类,

Person p;
Teacher t;
Student s;
p, t and s are all non-null.
if(t  instanceof  Person) { s = (Student)t; }这个语句导致的结果是什么(          )
A. 将构造一个Student对象。    B. 表达式合法。

C. 编译时非法。                       D. 编译时合法而在运行时可能非法。

32、给出下面的类:哪个表达式返回true。(          )

public class Sample{
long length;
public Sample(long l){ length = l; }
public static void main(String arg[]){
Sample s1, s2, s3;
s1 = new Sample(21L);
s2 = new Sample(21L);
s3 = s2;
long m = 21L;
}
}

A. s1 == s2;    B. s2 == s3;    C. m == s1;    D. s1.equals(m).

二、填空题:

1、public class Jtest{

int m=1;

int i=3;

void Jtest(){

m=2;

i=4;

}

public static void main(String[] args){

Jtest app=new Jtest();

System.out.println(app.m+”,”+app.i);

}

}

写出输出:                                    

2、public class Test {

public static void main(String[] args) {

int a=99;

oper(a);

System.out.print(a);

}

static void oper(int b){

b=b+100;

}

}

写出输出:                                    

3、public class Test {

public static void main(String[] args) {

String a=new String(“A”);

String b=new String(“B”);

oper(a,b);

System.out.print(a+”,”+b);

}

static void oper(String c,String d){

c.concat(“B”);

d=c;

}

}

写出输出:                                    

4、public class Test {

public static void main(String[] args) {

StringBuffer a=new StringBuffer (“A”);

StringBuffer b=new StringBuffer (“B”);

oper(a,b);

System.out.print(a+”,”+b);

}

static void oper(StringBuffer c,StringBuffer d){

c.append(“B”);

d=c;

}

}

写出输出:                                    

三、问答题

1、访问修饰符“public/private/protected/缺省的修饰符”的使用范围

 

 

 

 

2、ArrayList和Vector的区别,HashMap和Hashtable的区别

 

 

 

3、谈谈final, finally, finalize的区别

 

 

 

4、Overload和Override的区别

 

 

 

 

5、说明抽象类与接口的区别

 

 

 

 

 

评论列表
文章目录