Object Oriented Programming Methodology Using Java: Prof: Deepak Gaikar (Computer Department) RGIT-Mumbai
Object Oriented Programming Methodology Using Java: Prof: Deepak Gaikar (Computer Department) RGIT-Mumbai
Object Oriented Programming Methodology Using Java: Prof: Deepak Gaikar (Computer Department) RGIT-Mumbai
Using Java
Function-4 Function-5
Object A Object B
Data Data
Communication
Functions Functions
Object C
Data
Functions
Basic Concepts of Object-Oriented
Programming
• Objects
• Classes
• Data Abstraction and Encapsulation
• Inheritance
• Polymorphism
• Dynamic Binding
• Message Passing
Objects in OOP
• Object are the basic run-time entities in an
object-oriented system.
• They may represent a person, a place ,
a bank account, a table of data or
any item that the program has to handle.
• Objects take up space in the memory and
have an associated address like a structure
in C.
• When a program is executed, the objects
interact by sending messages to one another
OBJECT
HAS DOES
color bounce
diameter roll
brand
properties behavior
Objects examplein OOP
If there are two objects customer and account
then the customer object may send a message to
account object ..requesting for the bank balance.
Object : CUSTOMER Object :ACCOUNT
DATA DATA
AC No. AC No.
Name of AC Holder AC Balance
Address Type of Account
FUNCTIONS FUNCTIONS
Deposit Account Balance
Withdrawal
AC Balance Display
Classes
• A class is user-defined data type which contains
data members and member functions...Members
function operate those data Members.
• Classes are user defined data types and behaves
like the built in type of a programming language.
• Once a class has been defined, we can create any
number of objects belonging to that class. Thus a
class is collection of objects of similar type.
• class is collection of similar kind of objects.
Classes :The entire set of data & code of an object can be
made a user-defined data type with the help of a class. Objects
are actually variable of the type class
OBJECT
HAS DOES
color bounce
diameter roll
brand
properties behavior
Classes
• class is a collection of fields (data) and
methods (procedure or function) that
operate on that data.
• Class are just like the blueprints of objects
that model real world things.
• one of advantage of using classes is that
once you have created a class for a certain
type of object you can reuse that class in any
project.
Pr
of.
D
ee
pa
k
Ga
ika
r
A class Is defined by 3 element
1.A unique class name
2.Data members or attributes
3.Member functions or methods
circlecle
centre
radius
circumference()
circumference()
area()
Circle
centre
radius
circumference()
area()
Prof.Deepak Gaikar
rubaim.khan.kotye@ericsson.com
A class describes an object
OBJECT
HAS DOES
color bounce
diameter roll
brand
properties behavior
Prof.Deepak Gaikar
a class describes an object
Class ball
String color;
float diameter;
String brand;
OBJECT
void bounce(float h)
void roll (float d)
HAS DOES
color bounce
diameter roll
brand
properties behavior
Prof.Deepak Gaikar
Circle ball
String color;
Data members
Float diameter;
String brand;
Prof.Deepak Gaikar
The syntax for defining class in c++ :
class class_name
{
private :
variable declarations;
functions declarations;
public:
variable declarations;
functions declarations;
};
void main()
{
class_name variabale_name;
….
}
The syntax for defining class in java :
class class_name
{
private
variable declarations;
functions declarations;
public
variable declarations;
functions declarations;
}
class mainclass_name
{
public static void main(String args[])
{
class_name variabale_name=new class_name( );
….
}
}
example of class in Java
class ball class ballmain
{ {
String color; public static void main (String args[ ])
float diameter; {
String brand; // Following statement would
void bounce(float h) create an object
{ } ball b=new ball( );
void roll (float d) }
{ } }
}
Pr
of.
D
ee
pa
k
Ga
ika
r
Pr
of.
D
ee
pa
k
Ga
ika
r
Pr
of.
D
ee
pa
k
Ga
ika
r
Pr
of.
D
ee
pa
k
Ga
ika
r
Pr
of.
D
ee
pa
k
Ga
ika
r
Ball b =new Ball();
b.color=“white”;
b.diam=2.0f;
b.brand=“nike”; Pr
of.
D
b.bounce(); ee
b.boll(); pa
k
Ga
ika
r
Pr
of.
D
ee
pa
k
Ga
ika
r
Pr
of.
D
ee
pa
k
Ga
ika
r
Pr
of.
D
ee
pa
k
Ga
ika
r
OBJECT
Properties Behavior
i.e data member i.e method
Pr
of.
D
ee
pa
k
Ga
ika
r
Basic Concepts of OOP
Data Abstraction and Encapsulation continue …
oThe wrapping up of data and functions into a
single unit is known as encapsulation.
class.
o It supports the concept of hierarchical
classification.
o Inheritance is a compile-time mechanism in Java
that allows you to extend a class (called the
baseclass or superclass) \ with another class
(called the derived class or subclass) or
o The mechanism of deriving a class from another
existing class is called as inheritance .
o Access specifies:- public, protected ,private,
default.
Property Inheritance
Bird
Attributes:
Feathers
Lay eggs
Attributes: Attributes:
------------ ------------
------------ ------------
Message Passing
o A message for an object is a request for
execution of a procedure.
o The receiving object will invoke a function
and generates results.
o Message passing involves :
o The name of the Object.
o The name of the Function.
o The information to be send.
Benefits of OOP
• Inheritance – eliminate redundant code and
extend the use of existing classes.
• We can build programs from the standard
working module.
• Data hiding helps the programmer to build
secure programs that can not be invade by code
in other parts of the program.
• Multiple instances of an objects can co-exists
with out any interference.
Benefits of OOP
• It is easy to partition the work in a
project based on objects.
• Object-oriented system can be easily
upgraded from small to large systems.
• Message passing techniques for
communication between objects makes
the interface descriptions with external
systems much simpler.
• Software complexity can be easily
managed.
Characteristics of Object-Oriented Programming
• Importance is on data.
• Programs are divided into objects.
• Objects may communicate with each other
through functions.
• Data structures are designed such that they
characterize the objects.
• Functions that operate on the data of an object
are tied together in the data structure.
• Data is hidden and can not be accessed by
external functions.
• New data and functions can be added easily
whenever necessary.
Difference Between Procedure Oriented Programming
(POP) & Object Oriented Programming (OOP)
Procedure Oriented Object Oriented
Programming Programming
Access POP does not have any access OOP has access specifies named
Specifiers specifier. Public, Private, Protected, etc.
In POP, Data can move freely In OOP, objects can move and
Data Moving from function to function in the communicate with each other
system. through member functions.
In OOP, overloading is
In POP, Overloading is not possible in the form of
Overloading
possible. Function Overloading and
Operator Overloading.