0% found this document useful (0 votes)
15 views5 pages

Chapter 2

In Java, a class serves as a blueprint for creating objects, defining their properties and behaviors. Objects are instances of classes that occupy memory and can have unique data, with each object characterized by attributes, methods, and identity. Classes act as factories for creating similar objects and are considered user-defined data types derived from existing types.

Uploaded by

Neeraj Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views5 pages

Chapter 2

In Java, a class serves as a blueprint for creating objects, defining their properties and behaviors. Objects are instances of classes that occupy memory and can have unique data, with each object characterized by attributes, methods, and identity. Classes act as factories for creating similar objects and are considered user-defined data types derived from existing types.

Uploaded by

Neeraj Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Chapter -2

Elementary concept of objects and


classes
Class in java:
The basic unit of OOP is a class. Class is a blue print of an
object which defines the properties and behavior of an object. It
may be viewed as a factory that produce similar objects. It is also
used to create new data type.

Declaration of class:
class class_Name
{
//data mambers
// Member Methods
}
Object:
Objects are the instance of a class. When an object is created, it
acquires memory space in the computer. It is created and eventually
destroyed – so they only live in the program for a limited time. There
can be more than one instance of an object. Each instance of an object
can hold its own relevant data.
The different components of an object are:
• characteristics or attributes or state
• Behaviour or methods
• Name of the object or identity
Creating object of a class:

<class_name> <space> <object_name>=new <space> <class_name()>;


Example:
class Test
{
public static void main(String[] args)
{
Test obj=new Test();
}
Creating object
}
Properties of class:
(i) class is an object factory:

class is used to create similar type of objects with


different characteristics and common behaviours.

(ii) class is an user defined data type:


A user defined data type is a derived data type from
existing data types. class is made up of some attributes(data
members) which are predefined data types. While creating
an object, we are essentially defining a variable whose size is
equal to the total size of all the predefined data types
included in the class. So class is a user defined data types.

You might also like