Java知识点陈列

1.下面哪些方法是可执行Java程序的入口方法(a,b,d)。

a)public static void main(String[] hello)

b)public static void main(String world[])

c)static public String main(String[] args)//返回值类型必须为空

d)static public void main(String[] test)

2.下面哪些属于Java中的引用类型(a,b,c,d)。

a)基本数据类型数组

b)接口

c)字符串

d)引用数据类型数组

3.下列哪些方式能创建新的对象(a,b,c,d)。

a)构造方法

b)反射

c)克隆

d)反序列化

4.下面关于Java语言中多态的描述正确的是(a,b,c,d)。

 

a)重写是实现运行时多态性的手段

b)重载是实现编译时多态性的手段

c)封装、继承和多态是面向对象编程的重要支柱

d)多态是指相同的行为不同的表现

5.下面关于抽象类和接口的说法哪些是错误的(a,b,d)。

a)抽象类中只能包括抽象方法,必须写abstract关键字//抽象类不一定只包括抽象方法,说法太过于绝对

 

b)接口中的方法只能是抽象的,但不能写abstract关键字//abstract关键字可以省略,不能说成是不能写

 

c)接口中的方法只能是public的

 

d)接口中的方法只能是public的//接口中的方法的访问修饰符不一定都是public

6.当编译并运行下面程序时会发生什么结果(c)。

public class MyThread extends Thread {
public static void main(String args[]) {
    Thread t = new MyThread();
    t.start();
}

public void start(){

System.out.println(“执行start方法”);

}

public void run(){

System.out.println(“执行run方法”);

}

}

 

a)编译错误

b)运行异常

c)输出“执行start方法”

 

d)输出“执行run方法”

7.当编译和运行下面程序时会发生什么事情(d)。

public class Program {

public static void main(String args[]) {
         Program p = new Program();
         p.foo();

}

public void foo(){
int i;
System.out.println(i);

}

}

a)通过编译并输出0

 

b)产生编译错误

c)通过编译并输出null

 

d)通过编译但出现运行异常//在构造方法foo中,int i成员变量并没有赋初始值,所以在运行时会报NullPointerException。

 

8.要实现对象的克隆,可以实现下面哪些接口(a,c)。

 

a)Cloneable

b)Runnable

c)Serializable

d)Comparator

9.以下代码输出结果为(d ) 。

public class Test { 

public static String output = ""; 

    public static void foo(int i) { 

        try { 

            if(i == 1) { 

                throw new Exception(); 

            } 

            output += "1"; 

        } catch(Exception e){ 

            output += "2"; 

    return;

        } finally { 

            output += "3"; 

        output += "4"; 

    }

    public static void main(String args[]){ 

        foo(0); 

        foo(1); 

        System.out.println(output);  

}

a)1342

b)123

c)134234

d)13423

10.要遍历list对象中的元素,以下语句正确的是(a,b)。

List<String> list = new ArrayList<>();

list.add("a");

List<String> list = new ArrayList<>();

list.add("a");

a)while(it.hasNext())

   System.out.println(it.next());

b)for(int i = 0; i < list.size(); i++)

   System.out.println(list.get(i));

c)while(list.hasNext())

   System.out.println(list.next());

d)while(list.hasNext())

   System.out.println(list.next());

 

11.下面关于获取Class对象正确的代码是(a,b,c,d)。

a)Class.forName(“java.util.Date”)

b)String.class

c)int.class

d)int[].class;

 

12.下面关于垃圾回收说法正确的是(a,b,c,d)。

a)垃圾回收是一个后台线程

b)程序员不能干预垃圾回收

c)垃圾回收只能回收堆上的内存,无法释放外部资源(如打开的文件)

d)调用System类的gc方法不能确保垃圾回收器回收内存

 

posted @ 2015-05-15 23:04  安子静  阅读(170)  评论(0编辑  收藏  举报