当前位置:首页 > mooc课程 java 期末考试试卷
public static void fun(){ // some code... } } 如何使成员变量m 被函数fun()直接访问?
? ? ? ?
A、将private int m 改为protected int m B、将private int m 改为 public int m C、将private int m 改为 static int m D、将private int m 改为 int m 我的答案:C
4
类JOptionPane提供了几个产生标准对话框的方法,它们能够给用户提供有用的信息,具体的有:
? ? ? ?
A、closeDialog() B、openDialog() C、inputDialog() D、outputDialog() 我的答案:D 错误
5
运行下列程序,会产生什么结果: class Outer1{ private int a;
void foo(double d,final float f){ String s; final boolean b; class Inner{
void methodInner(){
System.out.println(“in the Inner“); } } }
public static void main(String args[]) {
Outer1 me=new Outer1(); me.foo(123,123); System.out.println(“outer“); } }
? ? ? ?
A、in the Inner outer B、outer C、in the Inner D、编译不通过 我的答案:B
6
编译及运行以下代码,下列选项哪个是正确的 public class Ref{
public static void main(String argv[]){ Ref r = new Ref(); r.amethod(r); }
public void amethod(Ref r){ int i=99; multi(r);
System.out.println(i); }
public void multi(Ref r){ r.i = r.i*2;
} }
? ? ? ?
A、编译错误 B、输出99 C、输出198 D、运行时出错 我的答案:A
访问权限练习已完成
1
如果任何包中的子类都能访问超类中的成员,那么应使用哪个限定词
?
A、
public
? ? ?
B、private C、protected D、transient 我的答案:A
2
不允许作为类及类成员的访问控制符的是:
? ? ? ?
A、public B、private C、static
D、protected
我的答案:B 错误
3
下面哪个修饰符修饰的方法只能被本类中的其他方法使用
? ?
A、protected B、static
? ?
C、private D、public
我的答案:C
4
如果类中的成员变量可以被同一包访问,则使用如下哪个约束符?
? ? ? ?
A、private B、public C、protected D、no modifier
我的答案:C 错误
5
某个类的成员变量可以被其子类访问,但不能被其他包中的类访问,该如何定义?
? ? ? ?
A、变量应该用public 做修饰。 B、变量应该用private做修饰。 C、变量应该用protected做修饰。 D、变量不需做任何修饰。 我的答案:C
6
关于被私有保护访问控制符private、 protected修饰的成员变量,以下说法正确的是( )
? ? ? ?
A、可以被三种类所引用:该类自身、与它在同一个包中的其他类、在其他包中的该类的子类 B、可以被两种类访问和引用:该类本身、该类的所有子类 C、只能被该类自身所访问和修改 D、只能被同一个包中的类访问 我的答案:C 错误
7
this关键字指的是?
? ? ? ?
A、当前对象指针 B、当前类的实例对象 C、当前对象引用 D、当前类的方法
共分享92篇相关文档