java中 is - a和 has - a都是什么啊?

来源:百度知道 编辑:UC知道 时间:2024/05/17 06:22:24
经常看到有提到什么is - a
has - a

这都是什么啊 谁能告诉我一下 最好详细一点
2楼那位朋友说的 00模式又是什么啊

我们以一道scjp考题为例,来讲解"is a"和"has a"的区别 :
Your chief Software designer has shown you a sketch of the new Computer parts system she is about to create. At the top of the hierarchy is a Class called Computer and under this are two child classes. One is called LinuxPC and one is called WindowsPC.
The main difference between the two is that one runs the Linux operating System and the other runs the Windows System. Under the WindowsPC are two Sub classes one called Server and one Called Workstation. How might you appraise your designers work?
a) Give the goahead for further design using the current scheme
b) Ask for a re-design of the hierarchy with changing the Operating System to a field rather than Class type
c) Ask for the option of WindowsPC to be removed as it will soon be obsolete
d) Change the hierarchy to remove the need for the superfluous Computer Class.
答案:b
解析:本题考察的知识点是“is a”和“has a”的区别。“is a”代表的是类之间的继承关系,比如PC机是计算机,工作站也是