1、如下代码运行结果是?(B)
class Person {
int age;
}
class Demo{
public static void main(String[] args){
Person p = new Person();
p.age = 1;
show(p);
System.out.println(p.age);
}
public static void show(Person p){
p.age =5;
}
}
A、 1
B、 5
C、 15
D、 0
2、给出如下程序,请问该程序的运行结果是( C )
class GrandFather {
public void show() {
System.out.println("我是爷爷");
}
}
class Father extends GrandFather {
public void method(){
System.out.println("我是爸爸");
}
}
class Son extends Father {}
class Test {
public static void main(String[] args) {
Son s = new Son();
s.method();
s.show();
}
}
A、 我是儿子 我是儿子
B、 我是爷爷 我是爸爸
C、 我是爸爸 我是爷爷
D、 我是爷爷 我是爷爷
3、以下说法正确的是( A )
A、 throw用于方法中抛出异常,后面写异常类的对象
B、 throw用于方法中抛出异常,后面写异常类的类名
C、 throws用于方法中抛出异常,后面写异常类的对象
D、 throws用于方法中抛出异常,后面写异常类的类名
4、下面哪个程序的运行结果是true? ( C )
A System.out.println("abc".equals(“Abc”));
B System.out.println("".equals(null));
C System.out.println("abc"=="ab"+"c");
D System.out.println("".equalsIgnoreCase(null));
5、以下定义不正确的是(B )
A、 List<String> list = new ArrayList<String>();
B、 List<String> list = new HashSet<String>();
C、 List<String> list = new LinkedList<String>();
D、 List<String> list = new Vector<String>();
6、下列程序的运行结果是( B )
import java.util.HashSet;
import java.util.Set;
public class Demo{
public static void main(String[] args) {
Set<String> set = new HashSet<String>();
set.add("嘉文");
set.add("赵信");
set.add("赵信");
System.out.println(set.size());
}
}
A、 3
B、 2
C、 1
D、 编译异常,set不能保存相同元素
7、Properties类中的哪个方法可以和IO流相关联( C )
A、 getProperty()
B、 setProperty()
C、 load()
D、 stringPropertyNames()
8、Math.random()说法正确的是(C )
A 返回一个不确定的整数
B 返回0或是1
C 返回一个随机的double类型数,该数大于等于0.0小于1.0
D 返回一个随机的int类型数,该数大于等于0.0小于1.0
9、读程序,选择程序的结果:( B )
class Student{
//姓名属性
String name;
//年龄属性
int age;
}
public class Test{
public static void main(String[] args){
//创建一个集合对象 存储学生
ArrayList<Student> stuList = new ArrayList<Student>();
//存储 二个同学
Student s1 = new Student();
s1.name = “Rose”;
s1.age = 30;
Student s2 = new Student();
s2.name =”Lily”;
s2.age = 18 ;
stuList.add(s1);
stuList.add(s2);
System.out.println(stuList.get(1).name);
}
}
A、 Rose
B、 Lily
C、 无显示结果
D、 null
10、假设项目根目录下有aa.txt,文本内容为”公司.程序员”,
请问执行下面程序执行后aa.txt里面的内容是( B )。
public static void main(String[] args) throws Exception {
FileOutputStream fos = new FileOutputStream("aa.txt");
fos.write("改变中国IT教育".getBytes());
fos.close();
}
A、什么都没有
B、改变中国IT教育
C、公司.程序员
D、乱码
2. 多选题
1、以下说法正确的是(AB )
A、 方法返回值是接口类型,可以返回它的实现类对象
B、 方法返回值是抽象类,可以返回他的子类的对象
C、 方法返回值是接口类型,这个方法必须定义为静态
D、 方法返回值是抽象类,这个方法必须定义为静态
2、分析如下Java代码,如果想在控制台上输出“B类的test()方法”,应在main中填入? AD
class A {
public void test() {
System.out.println("A类的test()方法");
}
}
class B extends A {
public void test() {
System.out.println("B类的test()方法");
}
public static void main(String args[]) {
}
}
A. A a = new B();
a.test();
B. A a = new A();
a.test();
C. B b = new A();
b.test();
D. new B().test();
3、如何自定义一个异常类(AB)
A 让这个类继承Exception
B 让这个类继承RuntimeException
C 让这个类继承Comparator
D 让这个类继承Comparable
4、System.currentTimeMillis方法说法正确的是(AC )
A 返回值是long类型
B 获取日期对象
C 获取当前时间的毫秒值
D 返回的是一个字符串
5、下列哪些集合属于Collection体系的子类( BD )
A. TreeMap
B. ArrayList
C. Hashtable
D. HashSet
6、Map集合可以通过哪些方式进行遍历? (BD )
A:直接通过迭代器即可
B:根据键找值的方式
C:根据for循环直接遍历
D:根据键值对对象找键和值的方式
7、如果需要从文件中读取数据,则可以在程序中创建哪一个类的对象( AD )
A. FileInputStream
B. FileOutputStream
C. DataOutputStream
D. BufferedInputStream
8、为了提高读写性能,用下面的哪些流?(AB )
A BufferedReader
B BufferedWriter
C InputStreamReader
D OutputStreamWriter
9. 请根据代码选出符合题意的说明()
//第一个方法
public static int getMax(ArrayList<Integer> list){
int max = list.get(0);
for(int i = 1 ;i<list.size;i++){
if(list.get(i)>max){
max = list.get(i);
}
}
return max;
}
//第二个方法
public static int getMin(ArrayList<Integer> list){
int min = list.get(0);
for(int i = 1 ;i<list.size;i++){
if(list.get(i)<min){
min = list.get(i);
}
}
return min;
}
请说明一下: 方法一实现的功能(C ) ,方法二实现的功能( B)
A: 求集合平均值
B: 求集合最小值
C: 求集合最大值
D: 求集合元素总和
10. 下列说法正确的是(ACE)。
class Test_3{
public static void main(String[] args) throws IOException {
copyTextFile();
}
public static void copyTextFile() throws IOException {
FileReader fr = new FileReader("c:\cn.txt");
FileWriter fw = new FileWriter("c:\copy.txt");
char[] buf = new char[1024]; //位置1
int len = 0;
while((len=fr.read(buf))!=-1){
fw.write( 位置3, 0 , 位置4 );
}
int ch = 0; //位置2
while((ch=fr.read())!=-1){
fw.write(ch);
}
fw.close();
fr.close();
}
}
A、 位置1自定义缓存区数组比2位置循环读写效率高
B、 位置2自定义缓存区数组比1位置循环读写效率高
C、 位置3应该填入的是buf对象
D、 位置3应该填入的是len对象
E、 位置4填入的是len对象