niusouti.com

单选题11. class Cup { }  12. class PoisonCup extends Cup { }  21. public void takeCup(Cup c) {  22. if(c instanceof PoisonCup) {  23. System.out.println(”Inconceivable!”);  24. } else if(c instanceof Cup) {  25. System.out.println(”Dizzying intellect!”);  26

题目
单选题
11. class Cup { }  12. class PoisonCup extends Cup { }  21. public void takeCup(Cup c) {  22. if(c instanceof PoisonCup) {  23. System.out.println(”Inconceivable!”);  24. } else if(c instanceof Cup) {  25. System.out.println(”Dizzying intellect!”);  26. } else {  27. System.exit(0);  28. }  29. }  And the execution of the statements:  Cup cup = new PoisonCup(); takeCup(cup);  What is the output?()
A

 Inconceivable!

B

 Dizzying intellect!

C

 The code runs with no output.

D

 An exception is thrown at runtime.

E

 Compilation fails because of an error in line 22.


相似考题
更多“11. class Cup { }  12. class PoisonCup extends Cup { }  21. ”相关问题
  • 第1题:

    如果有一个类MyFrame是Frame的子类,但它不能被实例化,请写出该类的声明头为( )。

    A.abstract class Frame. extends MyFrame

    B.abstract class MyFrame. extends Frame

    C.class MyFrame. abstract extends Frame

    D.class Frame. abstract extends MyFrame.


    正确答案:B
    B【解析】本题考查考生对类声明的理解。类声明的格式为:[修饰符]class类名[extends父类名][implements类实现的接口列表],其中口括起来的内容为可选项。关键字class是类定义的开始,类名应符合标识符命名规则。关键字extends指明该类是子类,它的父类名紧跟其后,子类与父类之间有继承关系。关键字implements指明该类实现的接口,后跟接口名列表。考生应注意掌握类声明的概念,虽然很简单,但容易漏掉有关修饰符。题目要求声明不能被实例化的类,因此应该是一个抽象类,用abstract作为修饰符。

  • 第2题:

    以下语句能顺利通过编译: final class class1 { } class class2 extends class1 { } 。()

    此题为判断题(对,错)。


    答案:错

  • 第3题:

    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

  • 第4题:

    10. abstract public class Employee {  11. protected abstract double getSalesAmount();  12. public double getCommision() {  13. return getSalesAmount() * 0.15;  14. }  15. }  16. class Sales extends Employee {  17. // insert method here  18. }  Which two methods, inserted independently at line 17, correctly complete the Sales class?()

    • A、 double getSalesAmount() { return 1230.45; }
    • B、 public double getSalesAmount() { return 1230.45; }
    • C、 private double getSalesAmount() { return 1230.45; }
    • D、 protected double getSalesAmount() { return 1230.45; }

    正确答案:B,D

  • 第5题:

    现在有两个类A、B,以下描述中表示B继承自A的是()

    • A、class A extends B
    • B、class B implements A
    • C、class A implements
    • D、class B extends A

    正确答案:D

  • 第6题:

    现自:  1.  interface Color {  }      2. interface Weight  {  }      3.  //insert code here    和以下足六个声明:  class Boat extends Color, extends Weight  {  }     class Boat extends Color and Weight  {  }      class Boat extends Color, Weight  {  }  class Boat implements Color,  implements Weight  {  }     class Boat implements Color and Weight  {  }      class Boat implements Color, Weight  {  }    分别插入到第3行,有多少行可以编译? () 

    • A、  0
    • B、  1
    • C、  2
    • D、  3

    正确答案:B

  • 第7题:

    What produces a compiler error?()  

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

    正确答案: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题:

    单选题
    11. class Cup { }  12. class PoisonCup extends Cup { }  21. public void takeCup(Cup c) {  22. if(c instanceof PoisonCup) {  23. System.out.println(”Inconceivable!”);  24. } else if(c instanceof Cup) {  25. System.out.println(”Dizzying intellect!”);  26. } else {  27. System.exit(0);  28. }  29. }  And the execution of the statements:  Cup cup = new PoisonCup(); takeCup(cup);  What is the output?()
    A

     Inconceivable!

    B

     Dizzying intellect!

    C

     The code runs with no output.

    D

     An exception is thrown at runtime.

    E

     Compilation fails because of an error in line 22.


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

  • 第11题:

    多选题
    Which two demonstrate an “is a” relationship?()
    A

    public interface Person { }  public class Employee extends Person { }

    B

    public interface Shape { }  public class Employee extends Shape { }

    C

    public interface Color { }  public class Employee extends Color { }

    D

    public class Species { }  public class Animal (private Species species;)

    E

    interface Component { }  Class Container implements Component ( Private Component[ ] children;  )


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

  • 第12题:

    单选题
    11. abstract class Vehicle { public int speed() { return 0; } }  12. class Car extends Vehicle { public int speed() { return 60; } }  13. class RaceCar extends Car { public int speed() { return 150; }}  ......  21. RaceCar racer = new RaceCar();  22. Car car = new RaceCar();  23. Vehicle vehicle = new RaceCar();  24. System.out.println(racer.speed() + “, „ + car.speed()  25. + “, “+ vehicle.speed());  What is the result?()
    A

     0, 0,0

    B

     150, 60, 0

    C

     Compilation fails.

    D

     150, 150, 150

    E

     An exception is thrown at runtime.


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

  • 第13题:

    定义一个类名为MyClass的类,并且该类可被所有类访问,那么该类的正确声明应为()

    A、private class MyClass extends Object

    B、class MyClass extends Object

    C、public class MyClass

    D、protected class MyClass extends Object


    答案:C

  • 第14题:

    10. public class ClassA {  11. public void count(int i) {  12. count(++i);  13. }  14. }  And:  20. ClassA a = new ClassA();  21. a.count(3);  Which exception or error should be thrown by the virtual machine?() 

    • A、 StackOverflowError
    • B、 NullPointerException
    • C、 NumberFormatException
    • D、 IllegalArgumentException
    • E、 ExceptionlnlnitializerError

    正确答案:A

  • 第15题:

    10. class Line {  11. public static class Point { }  12. }  13.  14. class Triangle {  15. // insert code here  16. }  Which code, inserted at line 15, creates an instance of the Point class defined in Line?() 

    • A、 Point p = new Point();
    • B、 Line.Point p = new Line.Point();
    • C、 The Point class cannot be instatiated at line 15.
    • D、 Line 1 = new Line() ; 1.Point p = new 1.Point();

    正确答案:B

  • 第16题:

    Assume that country is set for each class.  Given:  10. public class Money {  11. private String country, name;  12. public getCountry() { return country; }  13.}  and:  24. class Yen extends Money {  25. public String getCountry() { return super.country; }  26. }  27.  28. class Euro extends Money {  29. public String getCountry(String timeZone) {  30. return super.getCountry();  31. }  32. }  Which two are correct?()

    • A、 Yen returns correct values.
    • B、 Euro returns correct values.
    • C、 An exception is thrown at runtime.
    • D、 Yen and Euro both return correct values.
    • E、 Compilation fails because of an error at line 25.
    • F、 Compilation fails because of an error at line 30.

    正确答案:B,E

  • 第17题:

    定义一个类名为"MyClass.java"的类,并且该类可被一个工程中的所有类访问,那么该类的正确声明应为()。

    • A、private class My Class extends Object
    • B、class My Class extends Object
    • C、public class My Class
    • D、public class My Class extends Object

    正确答案:C,D

  • 第18题:

    下列类的定义中,错误的是()。

    • A、class x{....}
    • B、public x extends y{....}
    • C、public class x extends y{....}
    • D、class x extends y implements y1{....}

    正确答案:B

  • 第19题:

    11. class Person {  12. String name = “No name‟;  13. public Person(String nm) { name = nm; }  14. }  15.  16. class Employee extends Person {  17. String emplD = “0000”;  18. public Employee(String id) { empID = id; }  19. }  20.  21. public class EmployeeTest {  22. public static void main(String[] args) {  23. Employee e = new Employee(”4321”);  24. System.out.println(e.empID);  25. }  26. }  What is the result?() 

    • A、 4321
    • B、 0000
    • C、 An exception is thrown at runtime.
    • D、 Compilation fails because of an error in line 18.

    正确答案:D

  • 第20题:

    1. class Exc0 extends Exception { }  2. class Exc1 extends Exc0 { }  3. public class Test {  4. public static void main(String args[]) {  5. try {  6. throw new Exc1();  7. } catch (Exc0 e0) {  8. System.out.println(“Ex0 caught”);  9. } catch (Exception e) {  10. System.out.println(“exception caught”);  11. }  12. }  13. }  What is the result?()  

    • A、 Ex0 caught
    • B、 exception caught
    • C、 Compilation fails because of an error at line 2.
    • D、 Compilation fails because of an error at line 6.

    正确答案:A

  • 第21题:

    多选题
    定义一个类名为"MyClass.java"的类,并且该类可被一个工程中的所有类访问,那么该类的正确声明应为()。
    A

    private class My Class extends Object

    B

    class My Class extends Object

    C

    public class My Class

    D

    public class My Class extends Object


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

  • 第22题:

    单选题
    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;


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

  • 第23题:

    单选题
    10. public class ClassA {  11. public void count(int i) {  12. count(++i);  13. }  14. }  And:  20. ClassA a = new ClassA();  21. a.count(3);  Which exception or error should be thrown by the virtual machine?()
    A

     StackOverflowError

    B

     NullPointerException

    C

     NumberFormatException

    D

     IllegalArgumentException

    E

     ExceptionlnlnitializerError


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

  • 第24题:

    单选题
    What produces a compiler error?()
    A

     class A { public A(int x) {} }

    B

     class A {} class B extends A { B() {} }

    C

     class A { A() {} } class B { public B() {} }

    D

     class Z { public Z(int) {} } class A extends Z {}


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