Chap2-Object Oriented Programming Concept
Chap2-Object Oriented Programming Concept
Class
Collection of objects is called class. It is a logical entity.
Inheritance
When one object acquires all the properties and behaviors of a parent object,
it is known as inheritance. It provides code reusability. It is used to achieve
runtime polymorphism
Polymorphism
If one task is performed in different ways, it is known as polymorphism. For
example: to convince the customer differently, to draw something, for
example, shape, triangle, rectangle, etc.In Java, we use method overloading
and method overriding to achieve polymorphism .
Abstraction
Hiding internal details and showing functionality is known as abstraction. For
example, phone call, we don't know the internal processing. In Java, we use
abstract class and interface to achieve abstraction.
Encapsulation
Binding (or wrapping) code and data together into a single unit are known as
encapsulation. For example, a capsule, it is wrapped with different
medicines.
Aggregation
Aggregation is a way to achieve Association. Aggregation represents the
relationship where one object contains other objects as a part of its state. It
represents the weak relationship between objects. It is also termed as a has-
a relationship in Java. Like, inheritance represents the is-a relationship. It is
another way to reuse objects.
Composition
The composition is also a way to achieve Association. The composition
represents the relationship where one object contains other objects as a part
of its state. There is a strong relationship between the containing object and
the dependent object. It is the state where containing objects do not have an
independent existence. If you delete the parent object, all the child objects
will be deleted automatically.
Method Overloading
When there are multiple functions with the same name but different
parameters then these functions are said to be overloaded. Functions can
be overloaded by changes in the number of arguments or/and a change in
the type of arguments.
Method overriding
occurs when a derived class has a definition for one of the member functions
of the base class. That base function is said to be overridden.