Java程序设计(华东交通大学)章节测试答案
2025年11月21日
设有如下代码:interface IFace{ }class CFace implements IFace{ }class Base{ }public class ObRef extends Base{ public static void main(String argv[]){ ObRef obj = new ObRef(); Base b = new Base(); Object obj1 = new Object(); IFace obj2 = new CFace(); //Here }}则在 //Here处插入哪个代码将不出现编译和运行错误。 A.b=obj; B.obj1=obj2; C.obj=b; D.obj1=b;
设有如下代码:interface...
2025年11月21日
给出下面的不完整的类代码: class Person { String name, department; int age; public Person(String n){ name = n; } public Person(String n, int a){ name = n; age = a; } public Person(String n, String d, int a) { // doing the same as two arguments version of constructor // including assignment name=n,age=a department = d; } } 下面的哪些表达式可以加到构造方法中的”doing the same as…”处? A.this(n,a); B.this(name,age); C.name=n;age=a; D.Person(n,a);
给出下面的不完整的类代码: cl...
2025年11月21日
检查下面的代码:class E1 extends Exception{ };class E2 extends E1{ }class SuperQuiz6_2 { }public class Quiz6_3 extends SuperQuiz6_2{ public void f(Boolean flag) throws E1{ //一一X一一 }}下列的语句,哪—个可以放到–X–位置,而且保证编译成功。 A.throw new El(); B.throw new E2(); C.throw new object(); D.throw new Exception();
检查下面的代码:class E1...
2025年11月21日
以下程序的输出为? 1: class MyClass 2: { 3: static int maxElements; 4: 5: MyClass(int maxElements) 6: { 7: this.maxElements = maxElements; 8: } 9: 10: } 11: 12: public class Q19 13: { 14: public static void main(String[] args) 15: { 16: 17: MyClass a = new MyClass(100); 18: MyClass b = new MyClass(100); 19: 20: if(a.equals(b)) 21: System.out.println(“Objects have the same A.在第20行出错. equals()方法未定义. B.编译通过,在运行时20行出现异常 C.输出 “Objects have different D.输出 “Objects have the same A.不能在构造方法中调用super B.构造方法的第一条语句 C.任何地方 D.构造方法的最后一条语句
以下程序的输出为? 1: cla...
2025年11月21日
2025年11月21日
设有类定义如下: class InOut{ String s= new String(“Between”); public void amethod(final int iArgs){ int iam=5; iam++; class Bicycle{ public void sayHello(){ //Here } } } public void another(){ int iOther; } } 以下哪些语句可以安排在//Here处 ? System.out.println(s); A.System.out.println(iam); B. C.System.out.println(iArgs); D.System.out.println(iOther);
设有类定义如下: class I...