You are on page 1of 10

Object-Oriented

Programming
Presented By:
Sagar Gurung
Sailesh Sanal
Introduction To Object-Oriented
Programming
 Object means a real-world entity such as a pen, chair, table, computer,
watch, etc. Object-Oriented Programming is a methodology or paradigm
to design a program using classes and objects. It simplifies software
development and maintenance by providing some concepts:
• Object
• Class
• Polymorphism
• Inheritance
• Abstraction
• Encapsulation
An Example Of The Object-Oriented
Approach (Simulation)
 An Example Of The Object-Oriented Approach (Simulation)
Objects

 An entity that encapsulates data and behavior.


 data: variables inside the object
 behavior: methods inside the object

 You interact with the methods;


the data is hidden in the object.

 Constructing (creating) an object:


Type objectName = new Type(parameters);

 Calling an object's method:


objectName.methodName(parameters);
Class

 Collection of objects is called class. It is a logical entity.


 A class can also be defined as a blueprint from which you can create an individual
object. Class doesn't consume any space.
Polymorphism

 Ability for the same code to be used with different types of objects and
behave differently with each.

 System.out.println can print any type of object.


 Each one displays in its own way on the console.

 CritterMain can interact with any type of critter.


 Each one moves, fights, etc. in its own way.
Inheritance

 Inheritance in Java is a mechanism in which one object acquires all the


properties and behaviors of a parent object. It is an important part
of OOPs (Object Oriented programming system).
Abstract Class

 A hybrid between an interface and a class.


 defines a superclass type that can contain method declarations (like an interface) and/or method
bodies (like a class)
 like interfaces, abstract classes that cannot be instantiated
(cannot use new to create any objects of their type)
declaring an abstract class
public abstract class name {
...

// declaring an abstract method


// (any subclass must implement it)
public abstract type name(parameters);

}
Encapsulation/Information Hiding

Protects the inner-workings (data) of a class.


Only allow access to the core of an object in a controlled fashion (use the public parts to
access the private sections).
Typicallyit means public methods accessing private attributes via accessor and
mutator methods.
Controlled access to attributes: get data set data
Can (accessor (mutator
prevent invalid states
method) method)
Reduce runtime errors

public public public


method method method

private
data
Thank You

 Any Questions You can Ask Us.

You might also like