public interface A {  String DEFAULT_GREETING = “Hello World”;  public void method1();  }  A programmer wants to create an interface called B that has A as its parent. Which interface declaration is correct?() A、 public interface B extends A {}B、 public 

题目

public interface A {  String DEFAULT_GREETING = “Hello World”;  public void method1();  }  A programmer wants to create an interface called B that has A as its parent. Which interface declaration is correct?() 

  • A、 public interface B extends A {}
  • B、 public interface B implements A {}
  • C、 public interface B instanceOf A {}
  • D、 public interface B inheritsFrom A {}

相似考题

2.阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。[说明]本程序的功能是给公司的员工Tom,Jack,Green增加薪水。三人的职位分别是programmer, Manager,CEO。程序由6个类组成:WorkerTest是主类,programmer,Manager,CEO三个类,薪水增加的规则是 programmer的涨幅是5%;Manager的是10%;CEO也是Manager,但是它除了有Manager的涨幅,还有1000元的bonus。接口SalaryRaise提供了一个增加薪水的方法raise()。[java程序]public class WorkerTest {public WorkerTest( ) {}public static void main( String[] args) {Programmer programmer = new Programmer( "Tom" ,3000);Manager manager = new Manager( "Jack" ,4000);CEO ceo = new CEO( "Green" ,4000);Worker [] worker = new Worker[3];programmer, raise( );manager, raise( );ceo. raise( );worker[0] = programmer;worker [1] = manager;worker[2] = ceo;for ( int i = 0 ;i < worker, length; i + + ) {System. out. prinfln (" Name:" + worker [i]. getName ( ) +" \ tSalary:" + worker [i]. getSalary ());public interface SalaryRaise { void raise( ); }public class Worker {public String name;public double (1);public Worker( ) {}public String getName( ) {return name;}public void setName( String name) {this. name = name;}public double getSalary( ) {return salary;}public void setSalary(double salary) { this. salary = salary; }}public class Programmer extends Worker implements (2) {public Programmer( ) {}public void raise( ) {double pets=0.05;double sala = this. getSalary( ) * (1 + pers);this. setSalary (sala);public Programmer( Siring name, double salary) tthis. name = name;this. salary = salary;public class Manager extends (3) implements SalaryRaise {public Manager( ) { }public Manager(String name, double salary) {this. name = name;this. salary = salary;}public void raise( ) {double pets = 0.1;double sala = this. getSalary() * (1 + pers);this. setSalary(sala);}}public class CEO extends Manager implements SalaryRaise {public CEO() {}public CEO( String name,double salary) {this. name = name;this. salary = salary;}public void raise( ) {double bonus = 1000;(4);double sala = this. getSalary( );(5);this. setSalary(sala);}}

更多“public interface A {  String DEFAULT_GREETING = “Hello World”;  public void method1();  }  A programmer wants to create an interface called B that has A as its parent. Which interface declaration is correct?() A、 public interface B extends A {}B、 public i”相关问题
  • 第1题:

    interface Playable {

    void play();

    }

    interface Bounceable {

    void play();

    }

    interface Rollable extends Playable, Bounceable {

    Ball ball = new Ball("PingPang");

    }

    class Ball implements Rollable {

    private String name;

    public String getName() {

    return name;

    }

    public Ball(String name) {

    this.name = name;

    }

    public void play() {

    ball = new Ball("Football");

    System.out.println(ball.getName());

    }

    }

    这个错误不容易发现。


    正确答案:

     

    错。"interface Rollable extends Playable, Bounceable"没有问题。interface 可继承多个

    interfaces,所以这里没错。问题出在interface Rollable 里的"Ball ball = new Ball("PingPang");"。

    任何在interface 里声明的interface variable (接口变量,也可称成员变量),默认为public static

    final。也就是说"Ball ball = new Ball("PingPang");"实际上是"public static final Ball ball = new

    Ball("PingPang");"。在Ball 类的Play()方法中,"ball = new Ball("Football");"改变了ball 的

    reference,而这里的ball 来自Rollable interface,Rollable interface 里的ball 是public static final

    的,final 的object 是不能被改变reference 的。因此编译器将在"ball = new Ball("Football");"

    这里显示有错。

  • 第2题:

    Which three demonstrate an “is a” relationship?() 

    • A、 public class X {  }     public class Y extends X { }
    • B、 public interface Shape { }     public interface Rectangle extends Shape{ }
    • C、 public interface Color { }     public class Shape { private Color color; }
    • D、 public interface Species { }     public class Animal { private Species species; }
    • E、 public class Person { }    public class Employee {      public Employee(Person person) { }
    • F、 interface Component { }     class Container implements Component {   private Component[] children; }

    正确答案:A,B,F

  • 第3题:

    A programmer needs to create a logging method that can accept an arbitrary number of arguments. For example, it may be called in these ways:  logIt(”log message 1 “);  logIt(”log message2”,”log message3”);  logIt(”log message4”, “log message5”, “log message6);  Which declaration satisfies this requirement?()

    • A、 public void logIt(String * msgs)
    • B、 public void logIt(String [] msgs)
    • C、 public void logIt(String... msgs)
    • D、 public void logIt(String msg1, String msg2, String msg3)

    正确答案:C

  • 第4题:

    Which is a method of the MouseMotionListener interface?()

    • A、 Public void mouseMoved(MouseEvent)
    • B、 Public boolean mouseMoved(MouseEvent)
    • C、 Public void mouseMoved(MouseMotionEvent)
    • D、 Public boolean MouseMoved(MouseMotionEvent)
    • E、 Public boolean mouseMoved(MouseMotionEvent)

    正确答案:A

  • 第5题:

    Which the two demonstrate an “is a” relationship?()

    • A、 public interface Person {}  Public class Employee extends Person {}
    • B、 public interface Shape {}  public interface Rectangle extends Shape {}
    • C、 public interface Color {}  public class Shape { private Color color; }
    • D、 public class Species {}  public class Animal { private Species species; }
    • E、 interface Component {} Class Container implements Component {private Component [] children;

    正确答案:B,E

  • 第6题:

    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,E

  • 第7题:

    1. interface A { public void aMethod(); }  2. interface B { public void bMethod(); }  3. interface C extends A,B { public void cMethod(); }  4. class D implements B {  5. public void bMethod() { }  6. }  7. class E extends D implements C {  8. public void aMethod() { }  9. public void bMethod() { }  10. public void cMethod() { }  11. }  What is the result?() 

    • A、 Compilation fails because of an error in line 3.
    • B、 Compilation fails because of an error in line 7.
    • C、 Compilation fails because of an error in line 9.
    • D、 If you define D e = new E(), then e.bMethod() invokes the version of bMethod()defined in Line 5.
    • E、 If you define D e = (D)(new E()),then e.bMethod() invokes the version of bMethod() defined in Line 5.
    • F、 If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9.

    正确答案:F

  • 第8题:

    多选题
    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;  )


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

  • 第9题:

    单选题
    Which is a method of the MouseMotionListener interface?()
    A

     Public void mouseMoved(MouseEvent)

    B

     Public boolean mouseMoved(MouseEvent)

    C

     Public void mouseMoved(MouseMotionEvent)

    D

     Public boolean MouseMoved(MouseMotionEvent)

    E

     Public boolean mouseMoved(MouseMotionEvent)


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

  • 第10题:

    单选题
    现有:   1. interface Animal {    2.   void eat();   3.  }    4.   5. // insert code here    6.   7. public class HouseCat implements Feline {    8.   public void eat() { }   9. }   和以下三个接口声明:   interface Feline extends Animal { }    interface Feline extends Animal { void eat(); }     interface Feline extends Animal { void eat() { } }    分别插入到第 5 行,有多少行可以编译?()
    A

     0

    B

     1

    C

     2

    D

     3


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

  • 第11题:

    单选题
    A programmer needs to create a logging method that can accept an arbitrary number of arguments. For example, it may be called in these ways:  logIt(”log message 1 “);  logIt(”log message2”,”log message3”);  logIt(”log message4”, “log message5”, “log message6);  Which declaration satisfies this requirement?()
    A

     public void logIt(String * msgs)

    B

     public void logIt(String [] msgs)

    C

     public void logIt(String... msgs)

    D

     public void logIt(String msg1, String msg2, String msg3)


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

  • 第12题:

    单选题
    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*/ } }


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

  • 第13题:

    A programmer needs to create a logging method that can accept an arbitrary number of arguments.Forexample,it may be called in these ways: logIt("log message 1"); logIt("log message 2”,”log message 3"); logIt("log message 4","log message 5","log message 6"); Which declaration satisfies this requirement()?

    • A、public void logIt(String*msgs)
    • B、public void logIt(String[]msgs)
    • C、public void logIt(String...msgs)
    • D、public voidl ogIt(Stringmsg1,Stringmsg2,Stringmsg3)

    正确答案:C

  • 第14题:

    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

  • 第15题:

    Which method must be defined by a class implementing the java.lang.Runnable interface? () 

    • A、 void run()
    • B、 public void run()
    • C、 public void start()
    • D、 void run(int priority)
    • E、 public void run(int priority)
    • F、 public void start(int priority)

    正确答案:B

  • 第16题:

    现有:  interface Data {public void load();}  abstract class Info {public abstract void load();}      下列类定义中正确使用Data和Info的是哪项?() 

    • A、 public class Employee implements Info extends Data { public void load(){/*dosomething*/}     }
    • B、public class Employee extends Inf.implements Data{ public void load() {/*do something*/}     }
    • C、public class Empl.yee implements Inf extends Data{ public void Data.1oad(){* do something*/}     public void load(){/*do something*/}     }
    • D、public class Employee extends Inf implements Data  {  public void Data.1oad()  {/*do something*/)     public void info.1oad(){/*do something*/}    }

    正确答案:B

  • 第17题:

    interface A { public int getValue() }  class B implements A {  public int getValue() { return 1; }  }  class C extends B {  // insert code here  }  Which three code fragments, inserted individually at line 15, make use of polymorphism?()

    • A、 public void add(C c) { c.getValue(); }
    • B、 public void add(B b) { b.getValue(); }
    • C、 public void add(A a) { a.getValue(); }
    • D、 public void add(A a, B b) { a.getValue(); }
    • E、 public void add(C c1, C c2) { c1.getValue(); }

    正确答案:B,C,D

  • 第18题:

    现有:   1. interface Animal {    2.   void eat();   3.  }    4.   5. // insert code here    6.   7. public class HouseCat implements Feline {    8.   public void eat() { }   9. }   和以下三个接口声明:   interface Feline extends Animal { }    interface Feline extends Animal { void eat(); }     interface Feline extends Animal { void eat() { } }    分别插入到第 5 行,有多少行可以编译?()  

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

    正确答案:C

  • 第19题:

    单选题
    public interface A {  String DEFAULT_GREETING = “Hello World”;  public void method1();  }  A programmer wants to create an interface called B that has A as its parent. Which interface declaration is correct?()
    A

     public interface B extends A {}

    B

     public interface B implements A {}

    C

     public interface B instanceOf A {}

    D

     public interface B inheritsFrom A {}


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

  • 第20题:

    单选题
    Which method must be defined by a class implementing the java.lang.Runnable interface? ()
    A

     void run()

    B

     public void run()

    C

     public void start()

    D

     void run(int priority)

    E

     public void run(int priority)

    F

     public void start(int priority)


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

  • 第21题:

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

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

    B

    public interface Shape {}  public interface Rectangle extends Shape {}

    C

    public interface Color {}  public class Shape { private Color color; }

    D

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

    E

    interface Component {} Class Container implements Component {private Component [] children;


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

  • 第22题:

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

    public class X {  }     public class Y extends X { }

    B

    public interface Shape { }     public interface Rectangle extends Shape{ }

    C

    public interface Color { }     public class Shape { private Color color; }

    D

    public interface Species { }     public class Animal { private Species species; }

    E

    public class Person { }    public class Employee {      public Employee(Person person) { }

    F

    interface Component { }     class Container implements Component {   private Component[] children; }


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

  • 第23题:

    多选题
    10. interface Jumper { public void jump(); }  ......  20. class Animal {}  ......  30. class Dog extends Animal { 31. Tail tail; 32. }  ......  40. class Beagle extends Dog implements Jumper {  41. public void jump() { }  42. }  .......  50. class Cat implements Jumper {  51. public void jump() { }  52. }  Which three are true?()
    A

    Cat is-a Animal

    B

    Cat is-a Jumper

    C

    Dog is-a Animal

    D

    Dog is-a Jumper

    E

    Cat has-a Animal

    F

    Beagle has-a Tail

    G

    Beagle has-a Jumper


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