Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
173 views

Object AND Classes: in Java

This document discusses objects and classes in Java. It defines an object as a runtime entity that represents real-world entities, containing both data and code. A class is a template that defines a new data type for objects, and contains members like variables and methods that objects can access. To create an object, a variable of the class type is declared, and then instantiated using the new operator, allocating memory and returning a reference to the new object.

Uploaded by

VinayKumarSingh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT or read online on Scribd
0% found this document useful (0 votes)
173 views

Object AND Classes: in Java

This document discusses objects and classes in Java. It defines an object as a runtime entity that represents real-world entities, containing both data and code. A class is a template that defines a new data type for objects, and contains members like variables and methods that objects can access. To create an object, a variable of the class type is declared, and then instantiated using the new operator, allocating memory and returning a reference to the new object.

Uploaded by

VinayKumarSingh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT or read online on Scribd
You are on page 1/ 9

OBJECT

AND
CLASSES
in JAVA

Praseetha V.V
Object-Oriented Programming
 Emphasis is on data rather than behavior.
 Programs are designed around objects.
 Data structures are designed such that they
characterize objects.
 Objects may communicate each other
through methods.
 New data and methods can be added easily
whenever needed.
Objects
 Objects are basic runtime entities.
 Object – A variable of class type.
 An object represents an entity from the
real-world in the model.
 Objects contain data and code to manipulate
the data.
 Eg: “a person”, “a place”, “a bank account”
 When a program is executed, objects interact
by sending messages to another.
 Considering ‘customer’ and ‘account’ as two
objects in a banking program, then the
‘customer’ object may send message to
‘account’ object requesting for the balance.
 The entire set of data and code of an object
can be made a user-defined data type using
the concept of a class.
Creating an Object
 First declare a variable of class type
 Second acquire an actual copy of the object
and assign it to that variable. We can do this
by using new operator
Rect r; //declare
r=new Rect(); //instantiate

Action Result

Declare Rect r; null


Rect
Instantiate r=new Rect(); object
Classes
 Class defines a new data type and an object
as a ‘variable’ of that data type.
 Class is a template for an object .
 Object is an instance of a class.
 A class thus is a collection of a objects of
similar type.
 The methods and variables defined in a class
are called members of the class.
 Eg: mango, apple, orange are the members
of the class fruit.
Basic form of class
definition
class classname
{
[variable declarations;]
[method declaration;]
}
class Rect class program
{ { public static
int length; void
//Field main(String
int breadth; args[ ])
void area() {
{ Rect r=new
System.out.printl Rect();
n("Area="+lengt
r.length=3;
h*breadth);
} r.breadth=4;
} r.area();
}

You might also like