题目内容

关于以下 application 的说明,正确的是( )1. class StaticStuff2. {3. static int x=10;4. static { x+=5;}5. public static void main(String args[ ])6. {7.System.out.println(“x=” + x);8. }9. static { x/=3;}10. }

A. 4 行与 9 行不能通过编译,因为缺少方法名和返回类型
B. 9 行不能通过编译,因为只能有一个静态初始化器
C. 编译通过,执行结果为:x=5
D. 编译通过,执行结果为:x=3

查看答案
更多问题

关于以下程序代码的说明正确的是():1.class HasStatic{2. private static int x=100;3. public static void main(String args[ ]){4. HasStatic hs1=new HasStatic( );5. hs1.x++;6. HasStatic hs2=new HasStatic( );7. hs2.x++;8. hs1=new HasStatic( );9. hs1.x++;10. HasStatic.x--;11. System.out.println(“x=”+x);12. }13.}

A. 5 行不能通过编译,因为引用了私有静态变量
B. 10 行不能通过编译,因为 x 是私有静态变量
C. 程序通过编译,输出结果为:x=103
D. 程序通过编译,输出结果为:x=102

下列哪种说法是正确的

A. 实例方法可直接调用超类的实例方法
B. 实例方法可直接调用超类的类方法
C. 实例方法可直接调用其他类的实例方法
D. 实例方法可直接调用本类的类方法

关于实例方法和类方法,以下描述正确的是:

A. 实例方法只能访问实例变量
B. 类方法既可以访问类变量,也可以访问实例变量
C. 类方法只能通过类名来调用
D. 实例方法只能通过对象来调用

给定如下代码,下面哪个可以作为该类的构造函数 ( )public class Test { ?}

A. public void Test() {?}
B. public Test() {?}
C. public static Test() {?}
D. public static void Test() {?}

答案查题题库