One of the advantages of an Object-Oriented programming language is code reuse. There are two ways we can do code reuse either by the vimplementation of inheritance (IS-A relationship), or object composition (HAS-A relationship). Although the compiler and Java virtual machine (JVM) will do a lot of work for you when you use inheritance, you can also get at the functionality of inheritance when you use composition.
IS-A Relationship:
In object-oriented programming, the concept of IS-A is a totally based on Inheritance, which can be of two types Class Inheritance or Interface Inheritance. It is just like saying "A is a B type of thing". For example, Apple is a Fruit, Car is a Vehicle etc. Inheritance is uni-directional. For example, House is a Building. But Building is not a House.
It is a key point to note that you can easily identify the IS-A relationship. Wherever you see an extends keyword or implements keyword in a class declaration, then this class is said to have IS-A relationship.
HAS-A Relationship:
Composition(HAS-A) simply mean the use of instance variables that are references to other objects. For example Maruti has Engine, or House has Bathroom.
Let’s understand these concepts with an example of Car class.
http://www.w3resource.com/java-tutorial/inheritance-composition-relationship.php
相关推荐
With the possible exceptions of boxer Muhammad Ali and baseball player Babe Ruth, no athlete has made a greater impact on American society-or in the world-than Michael Jordan. Follow the life of one ...
Examples and Matlab code now appear on a gray background for easy identification and advancd material is marked with an asterisk. The book is intended to be self-contained. No previous knowledge of ...
Though lack of exercise has major health consequences, researchers are now examining the additional and widespread health risk of the simple act of sitting for extended periods. With research from ...
A symmetry finder has been developed which uses the intensity-based method to search an image for compact regions which display some degree of mirror symmetry due to intensity similarities across a ...
SQLMemTable does not require BDE and provides all the TTable‘s functionssuch as Master/Detail relationship, Filtering, Searching, Sorting, Key, Range, BLOB fields, and has some advanced features ...
pairwise relationship can be either a similarity, a dissimilarity, or a distance function. This book studies several similarity-based learning approaches, such as nearest neighbor models, local ...
confirm that good governance has a significant and positive impact on the relationship between managerial roles and development roles to the personal development of public sector managers.
NIST Special Publication 800-160, Volume 2 focuses on the property of cyber resiliency, which has a strong relationship to security and resilience, but which provides a distinctive framework for its ...
(2) the structure of normal contact force inside a horizontal slug has a uniform, non-uniform, and uniform distributions in turn in the axial direction when the slug achieves a stable state from a ...
A stack is an area of memory in which program procedure or function call addresses and parameters are temporarily stored. In Process To run in the same address space. In-process servers are loaded ...
This is a textbook intended for use at the advanced undergraduate and introductory graduate levels, non-University training courses, as well as reference and self-study for security professionals....
The ideas generated, however, can be used indifferent settings, resulting in a general book on computer vision that reveals the fascinating relationship of three-dimensional geometry and the imaging ...
historically unilateral relationship between system designers and hardware designers. An efficient solution requires a design strategy which tightly incorporates implementation issues throughout the ...
A total variability subspace is learned from the development set and is used to estimate a low (and fixed) dimensional latent factor called the identity vector (i-vector) from adapted mean ...
and the National Canned Spam Act limits a mar keter's ability to send "unsolicited messages" to people with whom the company does not have a relationship. Accord ing to the research firm ...
Customer Relationship Management is a topic that has attracted the attention of both marketing practitioners and researchers over the last decade. Despite, or maybe due to, the attention drawn to ...
If c has n+1 components, the polynomial it represents is . Tips Note the relationship of this function to p = poly(r), which returns a row vector whose elements are the coefficients of the polynomial...
Its only relationship to HTTP is that its handshake is interpreted by HTTP servers as an Upgrade request. The WebSocket protocol makes possible more interaction between a browser and a web site, ...
A Database Has Data and Relationships Databases Create Information Database Examples Single-User Database Applications Multiuser Database Applications E-Commerce Database Applications Reporting and ...
Matthew Wilson has been working with it for over a decade, and during that time he has found inherent limitations that require skillful workarounds. In this book, he doesn't just tell you what's ...