2016-2017秋冬《Java应用技术》考试

来源:互联网 发布:知乎 约翰事件 编辑:程序博客网 时间:2024/04/27 20:14

考试周最后一门考试是JAVA应用技术,本以为读完Thinking in JAVA后,自己对JAVA SE的掌握已经比较熟练了,一测试发现还有不少要补的地方,做完试卷抄了一下不太确定的题目,记录下来。

1.Methods in an interface are default to be public abstract.
解析:
True.
接口中的方法默认修饰符是public abstract的,实现接口的类重写方法后访问修饰符必须是public的。

2.Using import to import all class in a package may slow down the compilation but has no effect on the run-time performance.
解析:
True.
用import导入多余的包会影响编译的效率,但是不会影响执行的效率。这里有一个误区,很容易理解为import一个目录就像和C一样把这个目录下的文件加载进来。其实import只是作为一个全名的补充机制,比如在a包下有class A,在b包下的class B要使用A类,这里写好import a.*;就可以直接用A aInstance = new A(),相当于import把A补全为了a.A aInstance = new a.A(),仅此而已,没有导入任何新东西。导入多余的不必要的包只是在编译的时候要花更多的时间去import的包里面去找,但是编译得到的字节码是完全一样的,import了没有用到的类在字节码里面也完全没有体现。所以import只是影响编译时间,不影响JVM的运行时间。java会自动检查java.lang包。
这个知识点没有学过,
参考资料:http://blog.csdn.net/tiwerbao/article/details/14110149

3.Awt/Swing can display the same among different platforms.
Both Awt and Swing support listener event model.
解析:
True.
Awt和Swing都是与平台无关的,且java.awt.event和javax.swing.event都是存在的。
swing是轻量级组件,用java编写的;awt是重量级组件,用C编写的;同样是重量级组件的还有JFrame、JDialog、JWindow 和 JApplet。

4.Which of the following is false?
A. Objects of an inner class can be used in the outer class only.
B. No static members are allowed in an inner class.
C. Inner class can access every member of the outer class.
D. Inner class cannot be defined as private.
解析:
A. 其他类可以访问具有相应访问权限(如public)的内部类
对非静态内部类的创建形式为A.B x = new A().new B();
对静态内部类的创建形式为A.B x = new A.B();
B. 内部类不能有非常量的静态域,static应当不依赖实例类而存在,但是内部类是依赖外部类而存在的。
如:

public class InnerClassDemo{    int x;    class A{        static int a = 0;       //这样写是不合法的.        static final int b=0;   //这样写是合法的    }}

C. 内部类可以访问外部类的成员变量和成员函数,因为在编译时,内部类已经获得了一个外部类的引用。
参考资料:http://blog.csdn.net/zhangjg_blog/article/details/20000769
D. 对于顶级类(外部类)来说,只有两种修饰符:public和默认(default)。因为外部类的上一单元是包,所以外部类只有两个作用域:同包,任何位置。因此,只需要两种控制权限:包控制权限和公开访问权限,也就对应两种控制修饰符:public和默认(default)。
内部类的上一级是外部类,那么对应的有四种访问控制修饰符:本类(private),同包(default),父子类(protected),任何位置(public)。当一个内部类使用了private修饰后,只能在该类的外部类内部使用。
不知道对这道题我的理解是不是正确的,望大家指正。

  1. Below is a function signature of write() in OutputStream: void write(int b);
    Now given code below, what would be size and the content of the output file?
int x = 0xdeadbeef;FileOutputStream out = new FileOutputStream("output");out.write(x);

OutputStream的write(int b)方法默认写的是低八位,输入输出流都是一个字节一个字节地写进写出,至于显示成什么样,那是编码和软件的事情了。

6.For PipedInputStream and PipedOutputStream, which statement below is correct?
A. An object of PipedInputStream is to be created based on an Object of PipedOutputStream.
B. An object of PipedOutputStream is to be created based on an Object of PipedInputStream.
C. PipedInputStream and PipedOutputStream are to be created independently and to be created later.
D. Data flows from PipedInputStream to PipedOutputStream.
解析:
平时学io没管道流用得太少了,看了这篇文章,有一些收获。
参考资料:http://blog.csdn.net/zlp1992/article/details/50298195

7.Given the code below:

Class B{}Class C extends B{}which of the function below is NOT able to accept objects of both List<B> and List<C>?A. void f(List<? extends B>)B. void f(List<B> list)C. void f(List list)D. void f(List<?> list)

B选项的写法只能接收包含B的List,如果子类也可以接收的话,A选项的写法就没什么意义了。

8.写出程序结果

enum EnumTry{    MON, TUE, WED, THU, FRI;    public static void main(String[] args)     {        for(EnumTry e: EnumTry.values()){        System.out.println(e+":"+e.toString()+":"            +e.ordinal()+":"+e.name());        }    }}

对枚举不熟悉啊…懂的人应该毫无难度。输出结果是
MON:MON:0:MON
TUE:TUE:1:TUE
WED:WED:2:WED
THU:THU:3:THU
FRI:FRI:4:FRI

其他题就没有记录了,印象里还有一道题考了匿名内部类的反射,考得很隐蔽。主要都集中在基础知识上了,多线程的题都很少,复习了很久的JDBC、Socket通信和设计模式根本就没有涉及…
基础还需要继续巩固!

谢谢!

0 0
原创粉丝点击