You are on page 1of 8

OBJECT ORIENTED

PROGRAMMING ( OPP )

COMPUTER SCIENCE

SUBMITTED BY SUBMITTED TO
Runidh Sunuwar Shravan Sir
Sci-XII “C”
Introduction on Object-Oriented
Programming
 Concept of OOP
Object-oriented programming is a programming model that
uses object to design applications and computer programs.

OOP focuses on the objects that developers want to


manipulate rather than the logic required to manipulate
them. This approach to programming is well-suited for
programs that are large, complex and actively updated or
maintained. This includes programs for manufacturing and
design, as well as mobile applications; for example, OOP
can be used for manufacturing system simulation software.
Programming languages like C++, java, javaScript, PHP,
C#, VB.Net, and Objective-C are object-oriented
languages.
The main concept of OPP are as
follow :
• Problem are divided into objects.
• It is not possible to access data freely.
• Data hiding is possible.
• It uses a bottom-up programming technique.
• It is easy to add new data and functions.
• Objects can exchange data through their function
whereas in structured programming, a program consists
of a list of instructions and the computer carries out.
• As a program grow even larger and more complex, a
structured programming approach begins to show signs
of strains, but OOP is implemented more simple, fast,
and secure.
• Data and functions are encapsulated into a single entity.
• In OOPs, we create classes, which have the power of
reusability i.e., these classes can be used by other
programmers whenever need.

 The main features of OPP are as follow:


• Object
• Class
• Inheritance
• Encapsulation
• Polymorphism
• Abstraction
 Object
An object is a concept or thing with defined boundaries that
are relevant to the problem we are dealing with.

 The object serves two proposes :


• It helps to understand the real world.
• It provides a practical basis for a computer
applications.
When we approach a programming problem in an object-
oriented language, the problem is divided into different
objects. An object consists of data and functions, functions
are used to perform the operations on data. The data
containing the object is called member data and the
function is called a member function. The member
functions can only access data through the object. So, it
provides data security.
 Class
A class is a collection of similar object that have the same
properties, common, behaviour, and relationships. The
user-defined objects are created using the class keyword.
The class is a blueprint that defines a nature of a future
object. An instance is a specific object created from a
particular class. Classes are used to create and manage
new objects and support inheritance—a key ingredient in
object-oriented programming and a mechanism of reusing
code.
Example:
Class Employee{
float salary = 40000;
}
 Inheritance:
Inheritance is a mechanism where a new class (subclass)
derives attributes and methods from an existing class
(superclass). This fosters code reusability and establishes
a hierarchical relationship between classes. Example:
Class Employee{
float salary = 40000;
}
class Programmer extends Employee{
int bonus = 10000;
public static void main(String[]args){
Programmer p = new Programmer();
System.out.println(“Programmer salary
is:”+p.salary);
System.out.println(“Bonus of
programmer :”+p.bonus);
}
 Polymorphism:
Polymorphism allows Java methods and objects to
assume multiple forms. It finds common use in method
overloading (same method name, different parameters)
and method overriding (same method name and
parameters in subclass as in parent class). Example:
class Animal{
public void animal Sound(){
System.out.println(“The animal makes a sound”);
}
}
class Pig extends Animal{
public void animal Sound(){
System.out.println(“The pig says: wee wee”);
}
}
class Dog extends Animal{
public void animal Sound(){
System.out.println(“The dog says: bow wow”);
}
}
Class Main{
public static void main(String[]args){
Animal myAnimal = new Animal();
Animal myPig = new Pig();
Animal myDog = new Dog();
myAnimal.animalsound();
myPig.animalsound();
myDog.animalsound();
}
}
 Encapsulation:
Encapsulation is a pivotal OOPs principle in Java. It
entails bundling data (attributes) and code (methods) into a
cohesive unit. Moreover, it limits direct access to an
object’s components, preventing inadvertent interference.
Techniques like using private variables and offering public
getter and setter methods exemplify Java OOPs
concepts put into practice.
 Abstraction
Data abstraction is the process of identifying properties
and methods related to a particular entity as relevant to the
application. Thus, it is the process of examining all the
available information about an entity to identify information
that is relevant to the application. By grouping objects into
classes, we are in fact performing data abstraction of a
problem. Common definitions are stored once per class
rather than once per instance of the class. Methods can be
written once for a class so that the objects in a class
benefit from code reuse.
 Advantages
Some of the advantages of using OOP are:
• The complexity of the software can be merged easily.
• The data hiding concept helps the programmer to build
secure programs.
• Through the class concept, we can define the user-
defined data types.
• The inheritance concept can be used to eliminate the
redundant code.
• OOP ties data elements more closely to the functions
that operate.

 Disadvantages
Despite the advantages, mentioned above, the
disadvantages of OOP are:
• Use of OOP is a wastage of time in the case of small
projects or codes.
• Object-oriented Programs are much larger than other
programs.
• Object-oriented Programs require a lot of work to
create. Specifically, a great deal of Planning goes into
an Object-oriented Program well before a single piece
of code is ever written.
• Object-oriented Programs are slower than other
programs, partially because of their size. Other aspects
of Object-oriented Programs also demand more system
resources, thus Slowing the program down.

You might also like