Why Do We Need Object‐Oriented Programming?
• Object Oriented Programming was developed because
limitations were discovered in earlier approaches to
• To appreciate what OOP does, we need to understand
what these limitations are and how they arose from
traditional programming languages.
POP Vs. OOP
Procedure Oriented Programming Object Oriented Programming
• In OOP, program is divided into parts called
• OOP has access specifiers named Public, Private,
• OOP provides Data Hiding so provides more
• In OOP, overloading is possible in the form of
Function Overloading and Operator Overloading.
• In OOP, data can not move easily from function to
function, it can be kept public or private so we can
control the access of data.
• Example of OOP are : C++, JAVA, VB.NET,
• In POP, program is divided into small parts called
• POP does not have any access specifier.
• POP does not have any proper way for hiding data
so it is less secure.
• In POP, Overloading is not possible.
• In POP, Most function uses Global data for sharing
that can be accessed freely from function to
function in the system.
• Example of POP are : C, VB, FORTRAN, Pascal.
• Code Reuse and Recycling: Objects created for Object Oriented Programs can easily be
reused in other programs.
• Design Benefits: Large programs are very difficult to write. Object Oriented Programs
force designers to go through an extensive planning phase, which makes for better designs
with less flaws. In addition, once a program reaches a certain size, Object Oriented
Programs are actually easier to program than non-Object Oriented ones.
• Software Maintenance: Programs are not disposable. Legacy code must be dealt with on
a daily basis, either to be improved upon (for a new version of an exist piece of software)
or made to work with newer computers and software. An Object Oriented Program is much
easier to modify and maintain than a non-Object Oriented Program. So although a lot of
work is spent before the program is written, less work is needed to maintain it over time.
• Binding means link between
procedure call and code to be
• When a method call is resolved
at compile time, it is known
as STATIC BINDING.
• While if method invocation is
resolved at runtime, it is known
as DYNAMIC BINDING OR LATE
Because of polymorphism, a reference variable of type Parent can hold an object of type
Child, which extends Parent. Now if you call a virtual method (not private, final or static) on
this object, then Compiler can not find actual method, because it could be the one, which is
defined in Parent class, or the one which Child has overridden. This call can only be resolved
at runtime, when actual object is available. That's why this is known as RUNTIME OR
On the hand, private, static and final methods are resolved at compile time, because compiler
knows that they can't be overridden and only possible methods are those, which are defined
inside a class, whose reference variable is used to call this method. This is known as STATIC
OR COMPILE TIME BINDING, all private, static and final methods are resolved using static
This concept is also closely related to method overloading and method overriding. As
dynamic binding happens when method overriding is possibility and overloaded method
calls are resolved at compile time, because they are always defined in same class.
• Class is a Blueprint for an Object.
• Object is instance of class or it is
created from class.
• Encapsulation is the mechanism binds code and data together, and keeps both safe
from outside interference and misuse.
• Encapsulation is protective cover that prevents the code and data from being accessed
by other code defined outside.
• The process of wrapping up of data (properties) and behavior (methods) of an object
into single unit. In plain English means to be enclosed in or as if in a capsule.
• The fields of a class can be made read-only or write-only.
• A class can have total control over what is stored in its fields.
• The user doesn’t know how the class stores data.
public void method1()
int i=0; //variable
public void method2()
int i=0; //variable
• Inheritance is the method creating the new class based on already existing class.
• The new desired class is called subclass or child class. The existing class is called parent
class or super class or base class.
• Inheritance is the process by which one object acquires the properties of another object.
• Ability to change form is known as Polymorphism.
• Polymorphism means “many forms”.
• Method overloading, method overriding, interfaces are the example of
• The same method name (method overloading) or operator
symbol (operator overloading) can be used in different contents.
• In method overloading, multiple methods having same name can
appear in a class, but with different signature.
• Java does not allow operator overloading yet + is overloaded for
class string. The ‘+’ operator can be used for addition as well as
• Add a1=new Add();
• Add a2=new Add(1,2);
• Add a3=new Add(1,2,3);
• Defining a method in subclass having the same name as a method in the
parent class is known as Overriding.
• Abstraction specifies necessary and sufficient descriptions rather than
• Abstraction is an essential element of Object Oriented Programming. Through
abstraction we can manage complexity.
• Abstraction means hiding the unnecessary data from users. Abstraction defines only
the essential characteristics of an object.
Summary of Object Oriented Programming Concepts
• Everything is an Object.
• Computation is performed by objects communicating with each other, requesting
that other objects perform actions.
• Each object has its own memory, which consist of other objects.
• Every object is an Instance of a class. A class simply represents a grouping of
similar objects, such as integers or lists.
• The class is the responsible for behaviour associated with an object. That is, all
objects that are instance of the same class can perform the same action.
• Classes are organized into a singly rooted tree structure, called the Inheritance