多选题Which the two demonstrate an “is a” relationship?()Apublic interface Person {}  Public class Employee extends Person {}Bpublic interface Shape {}  public interface Rectangle extends Shape {}Cpublic interface Color {}  public class Shape { private Color

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

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

interface A{

int x = 0;

}

class B{

int x =1;

}

class C extends B implements A {

public void pX(){

System.out.println(x);

}

public static void main(String[] args) {

new C().pX();

}

}


正确答案:

 

错误。在编译时会发生错误(错误描述不同的JVM 有不同的信息,意思就是未明确的

x 调用,两个x 都匹配(就象在同时import java.util 和java.sql 两个包时直接声明Date 一样)。

对于父类的变量,可以用super.x 来明确,而接口的属性默认隐含为 public static final.所以可

以通过A.x 来明确。

第2题:

下列哪个类声明是正确的? ( )

A.abstract class G2 extends superClass1,superClass2{...}

B.abstract public class classmates{...}

C.public final class NewClass extends superClass implemnets Interface1{...}

D.public abstract class String{...}


正确答案:C
解析:本题考查对类声明的掌握程度。选项A错误,Java不支持多重继承,故extends关键字后只能接一个父类;选项B错误,在类声明中public关键字必须位于abstract关键字前;选项C正确,声明了一个公有的不能继承的类,这个类的父类是superClass,并使用了Interfacel提供的接口,类不能声明为protected和pfivate属性且不以“;”结尾:选项D错误,String是Java中字符串的关键字,不能用于类名。

第3题:

Given:10. interface Data { public void load(); }11. abstract class Info { public abstract void load(); }Which class correctly uses the Data interface and Info class?()()

A.

B.

C.

D.

E.

F.


参考答案:A

第4题:

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

第5题:

public abstract class Shape {  int x;  int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  and a class Circle that extends and fully implements the Shape class. Which is correct?() 

  • A、 Shape s = new Shape(); s.setAnchor(10,10); s.draw();
  • B、 Circle c = new Shape(); c.setAnchor(10,10); c.draw();
  • C、 Shape s = new Circle(); s.setAnchor(10,10); s.draw();
  • D、 Shape s = new Circle(); s->setAnchor(10,10); s->draw();
  • E、 Circle c = new Circle(); c.Shape.setAnchor(10,10); c.Shape.draw();

正确答案:C

第6题:

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");"

这里显示有错。

第7题:

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 {}

正确答案:A

第8题:

下列选项中的接口声明正确的是______。

A.interface Shape{...}

B.abstract private interface Shape extends Area{...}

C.private interface Shape{...}

D.protected privated interface;


正确答案:A

第9题:

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

第10题:

现自:  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

更多相关问题