0% found this document useful (0 votes)
6 views15 pages

OOPs Concept

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views15 pages

OOPs Concept

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

The main principles of

*Data hiding is done by using access specifiers or


visibility modifiers. • public
• private
• protected
• The data is not accessible to the
outside world, and only those
functions, that are wrapped in the
class, can access it.
What is Abstraction?

Abstraction is a process which displays only the information needed and hides the unnecessary information.
Or representing essential features without including the background details.
Example: If we have to collect information about a student.
We collect the following information. Blood report form
• Name
Name : _________
• Class
• Address Class : _________
• Dob
• Fathers name Dob : ________
• Mothers’ names Address: ________
• Likes and dislikes
Blood Group: ___
• Hobby
• Blood group
We may not require every information that we have collected to fill out the application. So, we select the data that is
required to fill out the application. Hence, we have fetched, removed, and selected the data, the student information
from large data. This process is known as abstraction in the oops concept.

The main purpose of abstraction is data hiding.


Polymorphism in Java is a concept by which a single action or task is performed in different ways.
i.e. One name many forms.

Polymorphism is derived from 2 Greek words

Poly (many) Morph (forms)

Polymorphism in Java is performed by using method/function overloading.

Function overloading is when more than one method share the same name
with different signature.
Method overloading
or
Function overloading
One person can have different behavior.
For example, a person acts as an employee
in the office, a customer in the shopping
mall, a passenger in bus/train, a student in
school, and a son at home.
This is polymorphism which means multiple
forms.
What is Inheritance?
• When a sub class inherits the properties (attributes and methods) of the super class it is called inheritance.
• Creating a new class from an existing class is called inheritance.
(We can reuse the methods and fields of the parent class.)

In a family, the child inherits certain features(attributes) or


behavior(method) from the mum or dad say height, complexion,
agility, temperament etc...
Class

A class is defined as a blueprint from which an object is created. (Class doesn't consume any space.)
Object
Any entity that has state and behavior is known as an object. For example, a
chair, pen, table, keyboard, bike, etc. It can be physical or logical.

An Object can be defined as an instance of a class.

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.

An object mainly consists of:

1.State: It is represented by the attributes (instance variables/data members) of an object.


2.Behavior: It is represented by the methods (functions/ member methods)of an object.

Method:
• A method is a collection of statements that perform some specific task.
• After performing a specific task a method may or may not return the result to the caller method.
• Methods allow us to reuse the code without retyping it, which is why they are considered time savers.
• In Java, every method must be part of some class, which is different from languages like C, C++, and
Python.
1. We all know that water is a liquid, but it changes
to solid when it frozen, and it changes to a gas
when it is heated at its boiling point.

2. The best example of polymorphism is human


behavior. One person can have different behavior.
For example, a person acts as an employee in the
office, a customer in the shopping mall, a passenger
in bus/train, a student in school, and a son at home.

3. We all use a single button to switch ON and OFF


the computer.

4. A boy starts his love by saying the word


“friendship” but the girl ends that love with the
same word “friendship”. The girl says that we will be
always good friends.

Here, the word “friendship” is the same but


attitude is different. This beautiful concept is
nothing but polymorphism.
Abstraction - In real life
Abstraction - representing essential features without including the background details or explanations.
Abstraction is the feature of extracting only the required information from objects.
mobile phone: to send/ receive messages, and phone calls, you just need to press the button or just need to touch the
screen but you do not have to worry about what is happening internally.
car breaks : you just need to press the paddle to stop the vehicle you don't need to know
how it works internally.

DATA HIDING
Example: Suppose we declared an Account class with a data member balance inside it. Here, the account balance is
sensitive information. We may allow someone to check the account balance but won't allow altering the balance
attribute.

Access Modifier

Access Modifiers provide some restrictions on the data and functions inside the class. There are
mainly three types of access modifiers considered in
1. private
2. public
3. protected
1. State

The state of an object means the current values of all of its attribute, mainly the following two types of states.

A car is defined by:


•Color
•Average
•Fuel type
•Speed
•Fuel level dynamic state
•Gear

You might also like