新浪笔试题

1. 不能用来修饰interface的有()

A.private B.public C.protected D.static

A C D,接口只能用public来修饰


2.System.out.println(-1>>>1) 输出什么.

A.-1 B.1 C. 2147483647 D. -2147483647

C java移位运算 >>>是无符号右移,左边补0 >>是有符号右移,左边补1


3. 下列有关Servlet的生命周期,说法不正确的是()。

A、在创建自己的Servlet时候,应该在初始化方法init()方法中创建Servlet实例。

B、在Servlet生命周期的服务阶段,执行service()方法,根据用户请求的方法,执行相应的doGet()或是doPost()方法。

C、在销毁阶段,执行destroy()方法后系统立刻进行垃圾回收。

D、destroy()方法仅执行一次,即在服务器停止且卸载Servlet时执行该方法。

4. 关于异常处理机制的叙述哪些正确()

A. catch部分捕捉到异常情况时,才会执行finally部分

B. 当try区段的程序发生异常时,才会执行catch区段的程序

C. 不论程序是否发生错误及捕捉到异常情况,都会执行finally部分

D. 以上都是

B C


下列程序有错误吗,错在那里
1.
public class Something {
void doSomething() {
private String s = "";
int i = s.length();
}
}

private等访问修饰符只能修饰成员变量而不是方法内部变量


2.
abstract class Something {
private abstract String doSomething ();
}

abstract虚方法必须在子类中实现,但是用private访问修饰符修饰之后就不能重写此方法



3.
public class Something {
public static void main(String[] args) {
Something s = new Something();
System.out.println("s.doSomething() returns " + doSomething());
}
public String doSomething() {
return "Do something ...";
}
}
main是静态方法,无法引用非静态的方法。正确的方式是通过s.doSomething来调用此类的非静态方法

4.
public class Something {
public static void main(String[] args) {
Other other= new Other();
new Something().addOne(other);
}
public void addOne(final Other other){
other.i++;
}
}
class Other{
public int i;
}

other用final修饰,变量只能赋值一次之后就不可以改变

5.
interface A {
int x = 0;
}
class B {
int x = 1;
}
class C extends B implements A {
public void printX() {
System.out.println(x);
}
public static void main(String[] args) {
new C().printX();
}

}



编程题:

1. jsp有哪些内置对象?作用分别是什么?

百度


2. 由于没有设置主键,表weibo有许多重复记录,写一个sql,把所有重复的记录删除掉,留下唯一的记录。
先选择出不重复的装到一个表里再重命名就可以了


3. 写一个方法,输入任意一个整数,返回它的阶乘.
太简单了,循环或递归


4. 写一个程序三个线程分别输出A,B,C, 顺序输出ABC十次.


5. 写一个二分查找算法,注意细节.

百度

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值