Object Oriented Programming Examples.
- pubudun

- Nov 21, 2019
- 3 min read
Updated: Nov 25, 2019
When you going to talk about OOP concept you should know live examples for that OOP concepts.
If interviewee knew OOP concepts with examples, that is additional advantage for that person. Because if interviewee know those thing Interviewer recognized he or she OK with basic programming principles very well.
“Object Oriented Programming is a programming concept that works on the principle that objects are the most important part of your program.”
Object Oriented Programming is a programming concept that works on the principle that objects are the most important part of your program. It allows users create the objects that they want and then create methods to handle those objects. Manipulating these objects to get results is the goal of Object Oriented Programming.
Object Oriented Programming popularly known as OOP, is used in a modern programming language like Java.

figure 01
Inheritance.
"OOP concept, which one object had the properties and behaviors of the parent objects."
In object-oriented programming, inheritance is the mechanism of basing an object or class upon another object or class, retaining similar implementation. Also defined as deriving new classes from existing ones and forming them into a hierarchy of classes.
Example:
When you compare old mobile phone and new smart phone, smart phone adopted lot of features from old one. Old phone can make calls, text a messages, play small games, do some calculations. New smart phone also have all those features and extra features as a High quality camera, play high quality online games, use social media, use high preforming applications, etc. In here smart phone inherit all features of old mobile phone and their have new features.
figure 02
Polymorphism.
“Polymorphism is the ability of an object to take on many forms.”
Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. Any Java object that can pass more than one IS-A test is considered to be polymorphic.
Example 1 :
In English, the verb run has a different meaning if you use it with a laptop, a foot race, and business. Here, we understand the meaning of run based on the other words used along with it.The same also applied to Polymorphism.

figure 03
Example 2 : Method overloading & Method over riding
Method overloading - Multiple methods have same name but different behaviors.
Method over riding - Sub class override the supper class.

figure 04
Abstraction.
"Is an act of representing essential features without including background details."
Abstraction is selecting data from a larger pool to show only the relevant details to the object. It helps to reduce programming complexity and effort. In Java, abstraction is accomplished using Abstract classes and interfaces. It is one of the most important concepts of OOP.
Example :
A Laptop consists of many things such as processor, motherboard, RAM, keyboard, LCD screen, wireless antenna, web camera, USB ports, battery, speakers etc. To use it, you don't need to know how internally LCD screens, keyboard, web camera, battery, wireless antenna, speakers works. You just need to know how to operate the laptop by switching it on. The intrinsic details are invisible. Think about if you would have to call to the engineer who knows all internal details of the laptop before operating it. This would have highly expensive as well as not easy to use everywhere by everyone. So here the Laptop is an object that is designed to hide its complexity.
figure 05
Encapsulation.
"OOP concept of wrapping the data & code only access that data withing same class."
It refers to the bundling of data with the methods that operate on that data. Encapsulation is used to hide the values or state of a structured data object inside a class, preventing unauthorized parties' direct access to them.
Example 1 :
capsule encapsulate several combinations of medicine. If combinations of medicine are variables and methods then the capsule will act as a class and the whole process is called Encapsulation.

figure 06
Example 2 : Access modifiers
Their have three main access modifiers,
Privet - Limited access within class.
Public - Common access.
Protected - Limited access withing class & child class.

figure 07

















Comments