场景:
刷题,上大分......错题
错题1描述:
指出下列程序运行的结果()
public class Example{
String str = new String("good");
char[ ] ch = { 'a' , 'b' , 'c' };
public static void main(String args[]){
Example ex = new Example();
ex.change(ex.str,ex.ch);
System.out.print(ex.str + " and ");
System.out.print(ex.ch);
}
public void change(String str,char ch[ ]){
str = "test ok";
ch[0] = 'g';
}
}
选项
A.good and abc
B.good and gbc
C.test ok and abc
D.test ok and gbc
原因分析:
这里传了两个地址值,第一个参数字符串改变引用,引用从堆空间指向字符串常量区。
数组也传了地址过去,所有索引值为0的元素会被改变。
答案:B
错题2描述:
java如何返回request范围内存在的对象?
选项如下:
A.request.getRequestURL()
B.request.getAttribute()
C.request.getParameter()
D.request.getWriter()
原因分析:
equest.getAttribute()方法返回request范围内存在的对象,
而request.getParameter()方法是获取http提交过来的数据。
getAttribute是返回对象,getParameter返回字符串。
答案:B
错题3描述:
以下哪个I / O类可以附加或更新文件
选项如下:
A.RandomAccessFile()
B.OutputStream()
C.DataOutputStream()
D.None of the above
原因分析:
RandomAccessFile 可以通过 seek(long pos) 方法去移动文件指针进行追加更新写入.
OutputStream() 是一个抽象类 不能直接实例化去写入
DataOutputStream() 也无法追加写入
答案:A
错题4描述:
以下代码可以使用的修饰符是:()
public interface Status {
/*INSERT CODE HERE*/ int MY_VALUE=10;
}
A.final
B.static
C.abstract
D.public
原因分析:
接口中字段的修饰符:public static final(默认不写)
接口中方法的修饰符:public abstract(默认不写)
答案:A B D
错题5描述:
下面的switch语句中,x可以是哪些类型的数据:()
switch(x)
{
default:
System.out.println("Hello");
}
选项:
A.long
B.char
C.float
D.byte
E.double
F.Object
原因分析:
jdk1.7之前byte,short ,int ,char
jdk1.7之后加入String
答案: B D