2021-08-26错题

场景:

刷题,上大分......

错题

错题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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

关于我成为程序员这档事

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值