JAVA语言基础笔试题-3
Question 1
Given:
1。 public class Team extends 。LinkedList {
2。 public void addPlayer(Player p) {
3. add(p);
4. }
5. public void compete(Team opponent) { /* more code here */ }
6。 }
7. class Player { /* more code here */ }
Which two are true? (Choose two.)
A. This code will compile.
B. This code demonstrates proper design of an is—a relationship.
C. This code demonstrates proper design of a has—a relationship.
D. A Java programmer using the Team class could remove Player
objects from a Team object.
答案: AD
考点: List接口实现,对象间泛化和关联关系
说明:
is a 关系一般用继承来表示,但此题这个继承从逻辑上不是太恰当.
Has a 关系一般来说表示某对象体内有其它对象的存在,该对象体现为属性形态,在UML中叫做关联关系。本题Team中虽然可以保存Player,但并非显式以属性形式存在。
由于LinkedList自带remove方法,(p) 来删除player对象。
Question 2
Which four are true? (Choose four。)
A。 Has—a relationships should never be encapsulated。
B. Has—a relationships should be implemented using inheritance.
C. Has—a relationships can be implemented using instance variables。
D. Is—a relationships can be implemented using the extends keyword.
E. Is-a relationships can be implemented using the implements
keyword。
F. The relationship between Movie and Actress is an example of an is—a
relationship.
G. An array or a collection can be used to implement a one—to—many
has-a relationship.
答案:CDEG
考点: 集合类型,对象间泛化和关联关系的理解
Has a 关系一般表示为一个类拥有一个属性,属性被封装是常见的事情。
Is a 关系一般用继承来表示,子类体内拥有父类部分。
接口的实现,也适用于 is a 关系来理解,因为接口从本质来说,也属于类的形态.
Question 3
Which two are true about has-a and is-a relationships? (Choose two。)
A. Inheritance(继承) represents an is—a relationship.
B。 Inheritance represents a has—a relationship.
C. Interfaces must be used when creating a has-a relationship.
D. Instance variables can be used when creating a has—a relationship.
答案:AD
考点:对象间泛化和关联关系的理解
Question 4
Given:
10。 interface Jumper { public void jump(); }
..。.。.
20. class Animal {}
。。.。..
30. class Dog e
JAVA基础面试题-3(答案版) 来自淘豆网m.daumloan.com转载请标明出处.