OOPs Concept in Java
OOPs Concept in Java
Topperworld.in
Object
Class
Inheritance
Polymorphism
Abstraction
Encapsulation
©Topperworld
Java Programming
❖ Object
Example: A dog is an object because it has states like color, name, breed, etc.
as well as behaviors like wagging the tail, barking, eating, etc.
❖ Class
• Collection of objects is called class. It is a logical entity.
• A class can also be defined as a blueprint from which you can create an
individual object. Class doesn't consume any space.
©Topperworld
Java Programming
❖ 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.
• Another example can be to speak something; for example, a cat speaks
meow, dog barks woof, etc.
©Topperworld
Java Programming
❖ 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.
• A java class is the example of encapsulation. Java bean is the fully
encapsulated class because all the data members are private here.
❖ Coupling
• Coupling refers to the knowledge or information or dependency of
another class.
• It arises when classes are aware of each other.
• If a class has the details information of another class, there is strong
coupling. In Java, we use private, protected, and public modifiers to
display the visibility level of a class, method, and field.
• You can use interfaces for the weaker coupling because there is no
concrete implementation.
©Topperworld
Java Programming
❖ Cohesion
❖ Association
Association represents the relationship between the objects. Here, one
object can be associated with one object or many objects. There can be
four types of association between the objects:
• One to One
• One to Many
• Many to One, and
• Many to Many
❖ Aggregation
©Topperworld