2021-09-17错题

场景:

在练习


错题

错题1描述:

下列java程序的输出结果为____。


public class Example{
    String str=new String("hello");
    char[]ch={'a','b'};
    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]='c';
    }
}

选项

A. hello and ab

B. hello and cb

C. hello and a

D. test ok and ab

E. test ok and cb

F. test ok and c


原因分析:

参考大佬的写法

在这里插入图片描述

答案: B


错题2描述:

在这里插入图片描述
选项:

A. InsideOne ei=eo.new InsideOne();

B. eo.InsideOne ei=eo.new InsideOne();

C. InsideOne ei=EnclosingOne.new InsideOne();

D. EnclosingOne.InsideOne ei=eo.new InsideOne();


原因分析:

从引入我们可以知道,InsideOne静态内部类 排除B

在这里插入图片描述
答案:A D


错题3描述:

往OuterClass类的代码段中插入内部类声明, 哪一个是错误的:

public class OuterClass{
    private float f=1.0f;
    //插入代码到这里
}

选项:

A. class InnerClass{
public static float func(){return f;}
}

B. abstract class InnerClass{
public abstract float func(){}
}

C. static class InnerClass{
protected static float func(){return f;}
}

D. public class InnerClass{
static float func(){return f;}
}


原因分析:

主要考核了这几个知识点:
1.静态内部类才可以声明静态方法
2.静态方法不可以使用非静态变量
3.抽象方法不可以有函数体

答案: A B C 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、付费专栏及课程。

余额充值