当前位置:首页 > Java程序设计期末考试题
给出以下代码,该程序的运行结果是什么? public class Example{ final int x=0; Example(){ x=1; }
final int aMethod(){ return x; } }
请选择所有正确答案:
代码编译错误,因为非final类中存在final方法。 代码编译成功。
代码编译错误,因为代码中对一个final变量x有改变其值的操作。 代码编译错误,如果去掉变量x前的final修饰符,可使代码编译通过。
给出以下代码,请问该程序的运行结果是什么? class Example{
public static void main(String args[]){ int a=5;
System.out.println(cube(a)); }
int cube(int theNum){ return theNum*theNum*theNum; } }
请选择一个正确答案:
代码编译失败,因为方法cube()已经在java.lang.Math类上定义过。 代码编译失败,因为方法cube()不是static方法。 代码编译成功,但运行期抛出异常。 打印输出125。
有代码如下,请补全: public class Example{
public enum Color{Red,Green,Blue}; public void foo(){ //在这里插入代码
System.out.println(c);
} }
for(Color c:Color.values()) for(Color c=RED; c 请问,以下哪些修饰符用于修饰变量,可使该变量属于类而不属于类实例? 请选择一个正确答案: static final abstract transient 设有下面两个类的定义: class Person { long id; // 身份证号 String name; // 姓名 } class Student extends Person { int score; // 入学总分 int getScore(){ return score; } } 则类Person和类Student的关系是( )。 A、包含关系 B、继承关系 C、关联关系 D、上述类定义有语法错误 对于以下类: class A{} class B extends A{} class C extends A{} public class Test { public static void main(String args[]) { A x= new A(); B y=new B(); C z=new C(); //此处插入一条语句 }
共分享92篇相关文档