Object Oriented Programming Examples in Java.

Home / Uncategorized / Object Oriented Programming Examples in Java.

Some real life Examples and Programming Examples of Object-oriented programming (OOP) concept in Java.

1 .Polymorphism :
The process of representing one form(Task) in multiple forms(Different-Different ways) is known as Polymorphism.

Real Life Example –
Suppose if you are in class room that time you behave like a student, when you are in market at that time you behave like a customer, when you at your home at that time you behave like a son or daughter, Here one person present in different-different behaviors.

Programming Example-
Method Overloading and Method Overriding.

2. Abstraction :
Abstraction is the concept of exposing only the required essential characteristics and behavior with respect to a context.
Real Life Examples –
Abstraction shows only important things to the user and hides the internal details, for example, when we ride a bike, we only know about how to ride bikes but can not know about how it work? And also we do not know the internal functionality of a bike.
Abstraction is ATM Machine; All are performing operations on the ATM machine like cash withdrawal, money transfer, retrieve mini-statement…etc. but we can’t know internal details about ATM.

Programming Example-
Interface and Abstract Class.

3. Encapsulation = Data Hiding + Abstraction.
Real Life Example – Looking at the example of a power steering mechanism of a car. Power steering of a car is a complex system, which internally have lots of components tightly coupled together, they work synchronously to turn the car in the desired direction. It even controls the power delivered by the engine to the steering wheel. But to the external world there is only one interface is available and rest of the complexity is hidden. Moreover, the steering unit in itself is complete and independent. It does not affect the functioning of any other mechanism.

Programming Example-
JavaBean Class which includes private variables and setters and getters.

4. Inheritance :
Real Life Example – Father gives his property to child , father got that properties from child’s grandfather , so child is the taker and father is giver , hence father works as a base class and child as derived class ,
• you can explain is that the child couldn’t give its property to father so Inheritance is one sided
• why it is needed? so you can explain like same properties needed in multiple class you need not to write multiple times.

Programming Example-
Method Overriding to achieve Run Time Polymorphism.

Leave a Reply

Your email address will not be published. Required fields are marked *