11. 下面的代码有没有问题? class Ellipse{ private double radiusA; private double radiusB; public Ellipse (double a,double b){ radiusA=a; radiusB=b; } } class Circle extends Ellipse{ }
A.没有问题
B.运行时创建Circle类型的对象出错,因为没定义构造函数
C.编译错误,因为Circle类没有定义构造函数
D.编译错误,Circle类的缺省构造函数需要调用Ellipse的缺省构造函数,参数不匹配
A B C D
D
12. 下面的代码中,横线上填写什么内容才没有错误? class Testl{ private static int classIndex=0; private______int index; public static void main(String[]args){ Test1 t=new Test1 (); System.out.println(______); } public______Test1 (){ index=++classIndex; } }
A.static index static
B.static classIndex 空白
C.空白 index 空白
D.空白 classIndex 空白
A B C D
D
13. 下面的代码中有什么错误? interface MyInterface{ int var=0; public void funl (); } public class MyClass implements MyInterface { public static void main(String[]args){ MyIntefface t=new Test1 (); t.var=1; t.fun1 (); } public void fun1 (){ System.out.println (var); } } A.第2行,变量var必须声明为public static final的 B.第7行,不能创建接口MyInterface类型的变量 c.第8行,不能为常量var赋值 D.第11行,方法funl必须声明为public static final的
A B C D
C
14. 现有两个类,父类为Person,子类为Chinese,Person中有如下的定义片段: …… String name="noname"; public Person () {name="one man";} …… Chinese中有如下的定义片段: public Chinese(int tmpage) { name="a chinese"; } public String getName () { return name; } 第三个类Demo是这样定义的: public class Demo { public static void main(String args[]) { Chinese c=new Chinese (25): System.out.println("This chinese's name is:”+c.getName ()); } } 程序进行编译执行时,会产生什么样的执行结果?
19. 下列代码的执行结果是。 public class text implements Runnable{ private int x; private int y; public static void main(String[]args){ text that—new text (); (new Thread (that)).start (); (new Thread (that)).start (); } public void run () { x++; y++; System.out.println("X="+X+",y="+y); } }
A.x=1,y=1;x=1,y=1
B.x=0,y=1;x=1,y=2
C.X=1,y=1;x=2,y=2
D.x=0,y=0;x=1,y=1
A B C D
C
20. 考虑下列代码: class Test (int i){ 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); } } 下列哪句描述是正确的?