1. Inheritance is one of the cornerstones of OOP because it allows for the creation
of hierarchical classifications
Using inheritance, you can create a general class at the top
This class may then be inherited by other, more specific classes
Each of these classes will add only those attributes and behaviors that are unique to it
Inheritance
2. In keeping with Java terminology, a class that is inherited is referred to as a superclass
The class that does the inheriting is referred to as the subclass
Each instance of a subclass includes all the members of the superclass
The subclass inherits all the properties of its superclass
Generalization/ Specialization
4. Association is a relationship between two objects
The association between objects could be
one-to-one
one-to-many
many-to-one
many-to-many
Types of Association
Aggregation
Composition
Example: A Student and a Faculty are having an association
Association
5. Aggregation is a special case of association
A directional association between objects
When an object ‘has-a’ another object, then you have got an aggregation between
them
Aggregation is also called a “Has-a” relationship.
Example: College has a Student Object
Aggregation
6. Composition
• Composition is a special case of aggregation
• In a more specific manner, a restricted aggregation is called composition
• When an object contains the other object, if the contained object cannot exist without the
existence of container object, then it is called composition
• Example: A class contains students. A student cannot exist without a class. There exists
composition between class and students
7. HAS-A relationship is expressed with containership
Containership simply means using instance variables that refer to other objects
Example:
The class House will have an instance variable which refers to a Kitchen object
It means that, House HAS-A Kitchen
Note that, something like Kitchen HAS-A House is not valid in this
context
HAS-A relationship
8. class A{
int money;
private int pocketMoney;
void fill(int money, int pocketMoney)
{
this.money = money;
this.pocketMoney = pocketMoney;
}
public int getPocketMoney(){
return pocketMoney;
}
}
A Possible Solution To The Program