OOPs Concept
OOPs Concept
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.
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.)
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.
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.
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.
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.