{
void test(int i){
System.out.println(“I am an int.”); }
void test(String s){
System.out.println(“I am a string.”);} public static void main(String args[]) {
Test t=new Test(); char ch=“y”; t.test(ch); } }
下列描述哪个正确?
? ? ? ?
A、程序将不会编译,因为空的方法不能被覆盖。
B、命令行t.test(ch);将不会编译,因为没有对应的方法。 C、代码将编译并输出以下结果: I am an String. D、代码将编译并输出以下结果: I am a int. 我的答案:D 错误
11
编译及运行以下代码,下列选项哪个是正确的 public class Sandys{ private int court;
public static void main(String argv[]){ Sandys s = new Sandys(99); System.out.println(s.court); } Sandys(int ballcount){
court=ballcount; } }
? ? ? ?
A、编译错误:the variable court is defined as private
B、编译错误:s is not initialized when the System.out method is called C、编译通过,没有输出 D、编译通过,输出99 我的答案:D
方法与变量使用已完成
1
关于static修饰符,以下哪个选项是正确的。
? ? ? ?
A、被static修饰符修饰的成员变量不能被修改。
B、在方法中创建的static变量,每次方法调用中对它的值做的修改都不能保留下来。 C、一个类的所有类对象共享这个类的static变量。 D、static修饰符只能用于修饰基本类型变量。 我的答案:C
2
方法内的变量:
? ? ? ?
A、一定在方法内所有位置可见 B、可能在方法内的局部可见 C、可以在方法外可见 D、方法外也可用 我的答案:B 错误
3
给出如下代码: class Test{ private int m;
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