You are on page 1of 3

Object-Oriented Programming

OOP stands for Object-Oriented Programming.

object-oriented programming is about creating objects that contain both data


and methods.

Tip: The "Don't Repeat Yourself" (DRY) principle is about reducing the
repetition of code. You should extract out the codes that are common for the
application, and place them at a single place and reuse them instead of
repeating it.

Classes and objects are the two main aspects of object-oriented


programming.

So, a class is a template for objects, and an object is an instance of a class.

When the individual objects are created, they inherit all the variables and
methods from the class.

Class 1:Add(),Sub() and Mul().

Class 2: created obj of class one and using dot(.) operator we inherit the
methods

Example:

Class Fruits

Object:

Apple,mango etc

Class Car:

Object:

Maruti,BMW,AUDI

Example:

If You are starting a company.


Employess:Noun
Adjective:Int Employe id,String Emp Dept,Double Salary.
Verbs:
getsalary();
getEmpid();
getEmpDep();

Object oriented 4 pillars:


Abstraction:
Abstraction is a process of hiding the implementation details and showing only
functionality to the user.
Best example: Mobile,car

Encapsulation:
Capsule:
Inheritance:
Polymorphisam: overloading and overriding

Abstraction:
 Core Object orientated Programming concept.
 Process of hiding the internal data and implementation from the outer world.
 Two Type:
1. Data Abstraction
2. Process Abstraction

Abstraction defines a model to create application component.


Data Abstraction:
When the object data is not visible to the outer world,it creates data abstraction.

Process Abstraction:

We don’t need to provide details about all the functionality of an object.


When we hide the internal implementation of the different functions involved in a user
Operation, it creates process abstraction.

How Abstraction is implemented in Java:


Its implemented through interface and abstract classes.

The abstract Keyword is a non-access modifier used for classes and methods.
Abstract Class-Its a restricted class that cannot create object.

1.An Abstract class can have abstract method and non abstract method

Encapsulation:

Binding the code and Data into single unit.


In encapsulation, a class's variables are hidden from other classes and can only be accessed
by the methods of the class in which they are found.
Student s1=new Student();

Student s2=new Student();


Student s3=new Student();
Student s4=new Student();
Roll no:0;

name=null;
Roll no:0;
name=null; Roll no:0;
name=null;

Constructor:
A constructor is a special method that is used to initialize objects.
It will have same name as Class Name.

You might also like