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
相关推荐
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 ...
This evolution has led to a situation where the world is increasingly shaped by machine-driven rules and norms, creating a "machine culture" that parallels human culture. As machines become more ...
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 ...
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 ...
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 ...
Each type has its specific advantages and is suited for different tasks. - **Applications in Pattern Recognition**: - **Image Recognition**: CNNs are particularly effective for recognizing patterns...
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 ...
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 ...
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, ...
As we learn more about the human brain, for example, we face new challenges in understanding the nature of consciousness and the relationship between mind and body. In the arts and humanities, the ...
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 ...
He has extensive experience in retail (point-of-sale and inventory) and customer relationship management (CRM) solutions. Mark currently serves as a senior software engineer for a nonprofit ...