标签:
1 Which
lines of the following will produce an error?
|
1
2
3
4
|
1. byte
a1 = 2,
a2 = 4,
a3;2. short
s = 16;3.
a2 = s;4.
a3 = a1 * a2; |
5 下面有关webservice的描述,错误的是?
7 以下代码的输出结果是?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
publicclass
B{ publicstatic
B t1 = newB(); publicstatic
B t2 = newB(); {
System.out.println("构造块"); } static {
System.out.println("静态块"); } publicstatic
void
main(String[] args) {
B
t = newB(); }}
正确答案: C 你的答案: A (错误)
静态块 构造块 构造块 构造块
构造块 静态块 构造块 构造块
构造块 构造块 静态块 构造块
构造块 构造块 构造块 静态块
静态块:用static申明,JVM加载类时执行,仅执行一次
构造块:类中直接用{}定义,每一次创建对象时执行
执行顺序优先级:静态块>main()>构造块>构造方法
静态块按照申明顺序执行,所以先执行publicstaticB t1 = newB();该语句创建对象,则又会调用构造块,输出构造块
接着执行public static B t1 = new B();输出构造块
再执行
static
{
System.out.println("静态块");
}输出静态块
最后main方法执行,创建对象,输出构造块 |
Servlet
–GenericServlet
–HttpServlet
–自己的servlet
ServletRequest
–HttpServletRequest
ServletResponse
–HttpServletResponse
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/persist213/article/details/47166435