场景:
在练习
错题
错题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