一、选择题(每题5分,共20分)
1、访问修饰符作用范围由大到小是(D)
A、 private-default-protected-public
B、 public -default-protected- private
C、 private- protected-default- public
D、public - protected- default-private
2、以下(D)不是Object类的方法?
A、clone()
B、finalsize()
C、toString()
D、hasNext()
3.Java中,以下(B)接口以键——值对的方式存储对象?
A、java.util.Collection
B、java.util.Map
C、java.util.List
D、java.util.Set
4、指出下列程序运行的结果()
Public class Example{
String str=new String(“good”);
char[] ch={‘a’,’b’,’c’ };
public static void main(String args[]){
Exampleex=new Example();
Ex.change(ex.str,ex.ch);
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
二、填空题(每题5分,共20分)
5、JAVA基本数据类型包括__ 字符类型char,布尔类型boolean,数值类型 ____.
6、Math.round(11.5)等于多少? 12 ,Math.round(-11.5)等于多少? -11
7、程序String str1="hello";String str2="he"+newString("llo");
System.out.println(str1==str2);的运行结果是: false
8、字符串分为两大类,一类是字符串常量,使用 String 类的对象表示;另一类是字符串变量,使用 StringBuffer 类的对象表示。
三 简答
9. 接口和抽象类的区别是什么?(10分)
答案:接口是公开的,里面不能有私有的方法或变量,是用于让别人使用的,而抽象类是可以有私有方法或私有变量的,
另外,实现接口的一定要实现接口里定义的所有方法,而实现抽象类可以有选择地重写需要用到的方法,一般的应用里,最顶级的是接口,然后是抽象类实现接口,最后才到具体类实现。
还有,接口可以实现多重继承,而一个类只能继承一个超类,但可以通过继承多个接口实现多重继承,接口还有标识(里面没有任何方法,如Remote接口)和数据共享(里面的变量全是常量)的作用.
10. 利用递归方法求5!
答案:
public class Test {
public static void main(String args[]) {
int x = 5;
int rs = Fac(x);
System.out.println("" + x + "! = " + rs);
}
public static long Fac(int x) {
if(x > 1)
return (x * Fac(x - 1));
else
return 1;
}
}
11. 编写多线程代码有几种实现方法?请用一段代码分别举例实现。
答案:
三种:
(1)继承Thread类,重写run函数