多选题class One {  void foo() {}  }  class Two extends One {   //insert method here  }  Which three methods, inserted individually at line 14, will correctly complete class Two?()Aint foo() { /* more code here */ }Bvoid foo() { /* more code here */ }Cpublic 

题目
多选题
class One {  void foo() {}  }  class Two extends One {   //insert method here  }  Which three methods, inserted individually at line 14, will correctly complete class Two?()
A

int foo() { /* more code here */ }

B

void foo() { /* more code here */ }

C

public void foo() { /* more code here */ }

D

private void foo() { /* more code here */ }

E

protected void foo() { /* more code here */ }


相似考题
更多“class One {  void foo() {}  }  class Two extends One {   //i”相关问题
  • 第1题:

    There are students in Class One than in Class Two.

    A、 many

    B、 more

    C、 most


    答案:B

    解析:本句意思:一班的学生比二班的多,句子中than说明两项内容进行比较,所以用比较级,而选项A是原级,选项C是最高级,所以应选B


  • 第2题:

    类clasg one在声明func成员函数时发生错误,出错原因是______。

    class one

    private:

    int a;

    public:

    void func(two&);

    };

    class two

    {

    private:

    int b;

    friend vold one::func(two&);

    };

    void one::func(two&r)

    {

    a=r.b;

    }


    正确答案:class one前没有声明语句class two;
    class one前没有声明语句class two; 解析:当一个类作为另一个类的成员函数、成员函数的参数或其他情况的时候,要确保编译器能正确解析。由于在rclass orle之前没有关于class two的任何说明,而在class one的func函数中却用了class two类的参数。因此是错误的。

  • 第3题:

    关于下列代码编译或执行结果的描述中,正确的是( )。 public class Test{ public static void main(String argsE]){ TcstThread pml=new TestThread("One") pml.start; TestThread pm2=new TestThread("Tw0") pm2.start; } } class TestThread extends Thread( private String sTname=""; TestThread(String s){ sTname=s; } public void run{ for(int i=O;i<2;i++){ try{ sleep(1000); }catch(InterruptedException e){} system.out.print(sTname+""); } } }

    A.不能通过编译,TestThread类中不能定义变量和构造方法

    B.输出One One Two Two

    C.输出Two One One Two

    D.选项B或C都有可能出现


    正确答案:D
    D。【解析】启动两个线程,线程之间没有进行同步,所以B和C均有可能。

  • 第4题:

    class One {  public One() { System.out.print(1); }  }  class Two extends One {  public Two() { System.out.print(2); }  }  class Three extends Two {  public Three() { System.out.print(3); }  }  public class Numbers{  public static void main( String[] argv) { new Three(); }  }  What is the result when this code is executed?() 

    • A、 1
    • B、 3
    • C、 123
    • D、 321
    • E、 The code rims with no output.

    正确答案:C

  • 第5题:

    In which two cases does the compiler supply a default constructor for class A?()  

    • A、 class A{}
    • B、 class A { public A(){} }
    • C、 class A { public A(int x){} }
    • D、 class Z {} class A extends Z { void A(){} }

    正确答案:A,D

  • 第6题:

    interface Data { public void load(); }  abstract class Info { public abstract void load(); }  Which class correctly uses the Data interface and Info class?() 

    • A、 public class Employee extends Info implements Data { public void load() { /*do something*/ } }
    • B、 public class Employee implements Info extends Data { public void load() { /*do something*/ } }
    • C、 public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }
    • D、 public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }
    • E、 public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }
    • F、 public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }

    正确答案:A

  • 第7题:

    class One {   public One foo() { return this; }  }  class Two extends One {  public One foo() { return this; }  }  class Three extends Two {   // insert method here  }  Which two methods, inserted individually, correctly complete the Three class?()

    • A、 public void foo() { }
    • B、 public int foo() { return 3; }
    • C、 public Two foo() { return this; }
    • D、 public One foo() { return this; }
    • E、 public Object foo() { return this; }

    正确答案:C,D

  • 第8题:

    10. interface Foo {}  11. class Alpha implements Foo {}  12. class Beta extends Alpha {}  13. class Delta extends Beta {  14. public static void main( String[] args) {  15. Beta x = new Beta();  16. // insert code here  17. }  18. }  Which code, inserted at line 16, will cause a java.lang.ClassCastException?() 

    • A、 Alpha a = x;
    • B、 Foo f= (Delta)x;
    • C、 Foo f= (Alpha)x;
    • D、 Beta b = (Beta)(Alpha)x;

    正确答案:B

  • 第9题:

    多选题
    Given:   10. class One {   11. void foo() { }   12. }   13. class Two extends One {   14. //insert method here   15. }   Which three methods, inserted individually at line 14, will correctly complete class Two?()
    A

    public void foo() { /* more code here */ }

    B

    private void foo() { /* more code here */ }

    C

    protected void foo() { /* more code here */ }

    D

    int foo() { /* more code here */ }

    E

    void foo() { /* more code here */ }


    正确答案: A,D
    解析: 暂无解析

  • 第10题:

    多选题
    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()
    A

    public class Circle implements Shape { private int radius; }

    B

    public abstract class Circle extends Shape { private int radius; }

    C

    public class Circle extends Shape { private int radius; public void draw(); }

    D

    public abstract class Circle implements Shape { private int radius; public void draw(); }

    E

    public class Circle extends Shape { private int radius;public void draw() {/* code here */} }

    F

    public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }


    正确答案: B,E
    解析: 暂无解析

  • 第11题:

    单选题
    class One {  public One() { System.out.print(1); }  }  class Two extends One {  public Two() { System.out.print(2); }  }  class Three extends Two {  public Three() { System.out.print(3); }  }  public class Numbers{  public static void main( String[] argv) { new Three(); }  }  What is the result when this code is executed?()
    A

     1

    B

     3

    C

     123

    D

     321

    E

     The code rims with no output.


    正确答案: B
    解析: 暂无解析

  • 第12题:

    多选题
    class One {   public One foo() { return this; }  }  class Two extends One {  public One foo() { return this; }  }  class Three extends Two {   // insert method here  }  Which two methods, inserted individually, correctly complete the Three class?()
    A

    public void foo() { }

    B

    public int foo() { return 3; }

    C

    public Two foo() { return this; }

    D

    public One foo() { return this; }

    E

    public Object foo() { return this; }


    正确答案: D,B
    解析: 暂无解析

  • 第13题:

    有如下程序: include using namespace std; class ONE { public: virtual void f() {

    有如下程序:

    include <iostream>

    using namespace std;

    class ONE

    {

    public:

    virtual void f() { cout << "1"; }

    };

    class TWO: public ONE

    {

    public:

    TWO() { cout << "2"; }

    };

    class THREE: public TWO

    {

    public:

    virtual void f() {TWO::f(); cout << "3"; }

    };

    int main()

    {

    ONE aa, *p;

    TWO bb;

    THREE cc;

    p=&cc;

    P->f();

    return 0;

    }

    执行上面程序的输出是【 】。


    正确答案:2213
    2213

  • 第14题:

    有下列程序:includeusing namespace std;class ONE{ public:virtual void f(){COUt<<"

    有下列程序:

    include<iostream>

    using namespace std;

    class ONE

    {

    public:

    virtual void f(){COUt<<"1";}

    };

    c1assTWO:public ONE

    {

    public:

    TWO(){cout<<"2";}

    };

    class THREE:public TWO

    {

    pub


    正确答案:2213
    2213 解析: 此题考查的是派生类的构造和析构函数。建立TWO的对象bb时,调用TWO的构造函数,输出“2”;THREE类又派生于TWO类,所以建立THREE类的对象cc时又会输出“2”;ONE类的对象指针p指向了THREE类的ONE类的虚函数f(),输出“1”;最后调用THREE类的f(),输出“3”。故最终的输出结果是2213。

  • 第15题:

    类class one 在声明func 成员函数时发生错误,出错原因是【 】。

    Class one

    {

    private:

    int a;

    public:

    void func(two& )

    };

    class two

    {

    private:

    int b;

    friend void one: :func(two & );

    };

    void one: : func(two& r)

    a=r.b;

    }


    正确答案:class one前没有声明语句class two;
    class one前没有声明语句class two; 解析:当一个类作为另一个类的成员函数、成员函数的参数或其他情况的时候,要确保编译器能正确解析。由于在class one之前没有关于class two的任何说明,而在class one的func函数中却用了class two类的参数。因此是错误的。

  • 第16题:

    public class SomeException {  } Class a:  public class a {  public void doSomething() { }  } Class b:  public class b extends a {  public void doSomething() throws SomeException { }  }  Which is true about the two classes?() 

    • A、 Compilation of both classes will fail.
    • B、 Compilation of both classes will succeed.
    • C、 Compilation of class a will fail. Compilation of class b will succeed.
    • D、 Compilation of class a will fail. Compilation of class a will succeed.

    正确答案:D

  • 第17题:

    class One {  void foo() {}  }  class Two extends One {   //insert method here  }  Which three methods, inserted individually at line 14, will correctly complete class Two?()

    • A、 int foo() { /* more code here */ }
    • B、 void foo() { /* more code here */ }
    • C、 public void foo() { /* more code here */ }
    • D、 private void foo() { /* more code here */ }
    • E、 protected void foo() { /* more code here */ }

    正确答案:B,C,E

  • 第18题:

    现有:  import java.util.*;      class AddStuff2  {  public static void main(String  []  args)  {      TreeSett=new TreeSet();      if (t.add("one"))      if (t.add("two"))     if (t.add ("three"))  add("four");  for (String s  :  t)      System.out.print (s);     }      }      结果为:()     

    • A、 one
    • B、 one three two
    • C、 one two three
    • D、 one two three four
    • E、 four one three two
    • F、编译失败

    正确答案:E

  • 第19题:

    public class Test {  public static void main(String args[]) {  class Foo {  public int i = 3; }  Object o = (Object)new Foo();   Foo foo = (Foo)o;  System.out.println(“i = “ + foo.i); }  }  What is the result?()  

    • A、 i = 3
    • B、 Compilation fails.
    • C、 A ClassCastException is thrown at line 6.
    • D、 A ClassCastException is thrown at line 7.

    正确答案:A

  • 第20题:

    Given:   10. class One {   11. void foo() { }   12. }   13. class Two extends One {   14. //insert method here   15. }   Which three methods, inserted individually at line 14, will correctly complete class Two?()

    • A、 public void foo() { /* more code here */ }
    • B、 private void foo() { /* more code here */ }
    • C、 protected void foo() { /* more code here */ }
    • D、 int foo() { /* more code here */ }  
    • E、 void foo() { /* more code here */ }

    正确答案:A,C,E

  • 第21题:

    单选题
    There are not_____students in Class One as in Class Two.
    A

    so many

    B

    so much

    C

    more

    D

    much more


    正确答案: A
    解析:

  • 第22题:

    单选题
    What is wrong with the following code?()   class MyException extends Exception {}   public class Qb4ab {   public void foo() {  try {  bar();  } finally {  baz();   } catch (MyException e) {}  }   public void bar() throws MyException {   throw new MyException();  }   public void baz() throws RuntimeException {   throw new RuntimeException();   }   }
    A

    Since the method foo() does not catch the exception generated by the method baz(), it must      declare the RuntimeException in its throws clause.

    B

    A try block cannot be followed by both a catch and a finally block.

    C

    An empty catch block is not allowed.

    D

    A catch block cannot follow a finally block.

    E

    A finally block must always follow one or more catch blocks.


    正确答案: B
    解析: 暂无解析

  • 第23题:

    单选题
    class Parent {     String one, two;  public Parent(String a, String b){     one = a;     two = b;    }  public void print(){ System.out.println(one); }    }  public class Child extends Parent {     public Child(String a, String b){     super(a,b);     }  public void print(){  System.out.println(one + " to " + two);     }  public static void main(String arg[]){     Parent p = new Parent("south", "north");     Parent t = new Child("east", "west");     p.print();     t.print();     }     }  Which of the following is correct?()
    A

     Cause error during compilation. 

    B

     south         east 

    C

     south to north     east to west    

    D

     south to north      east    

    E

     south     east to west


    正确答案: C
    解析: 这个题目涉及继承时的多态性问题,在前面的问题中已经有讲述,要注意的是语句t.print();在运行时t实际指向的是一个Child对象,即java在运行时决定变量的实际类型,而在编译时t是一个Parent对象,因此,如果子类Child中有父类中没有的方法,例如printAll(),那么不能使用t.printAll()。