0% found this document useful (0 votes)
5 views3 pages

Classes&Objects

In Java, a class serves as a blueprint for creating objects, encapsulating common characteristics and behaviors. Classes consist of data members, methods, constructors, nested classes, and interfaces, but do not occupy memory themselves. Objects are instances of classes that utilize the defined attributes and methods, as demonstrated in the provided example of a Room class.

Uploaded by

Shruti Patawar
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)
5 views3 pages

Classes&Objects

In Java, a class serves as a blueprint for creating objects, encapsulating common characteristics and behaviors. Classes consist of data members, methods, constructors, nested classes, and interfaces, but do not occupy memory themselves. Objects are instances of classes that utilize the defined attributes and methods, as demonstrated in the provided example of a Room class.

Uploaded by

Shruti Patawar
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/ 3

Classes and Objects

Java Classes
A class in Java is a set of objects which shares common characteristics/ behavior and common
properties/ attributes. It is a user-defined blueprint or prototype from which objects are created.
For example, Student is a class while a particular student named Ravi is an object.

Properties of Java Classes


1.Class is not a real-world entity. It is just a template or blueprint or prototype from which objects
are created.
2.Class does not occupy memory.
3.Class is a group of variables of different data types and a group of methods.
4.A Class in Java can contain:

• Data member
• Method
• Constructor
• Nested Class
• Interface
Syntax:
access_modifier class <class_name>
{
data member;
method;
constructor;
nested class;
interface;
}

Java Objects
Objects are the instances of a class that are created to use the attributes and methods of a class.
// Java Program for class and Object example
class Room
// data member (also instance variable)
int length;
int width;
public static void main(String args[])
{
Room r1 = new Room(); // creating an object of Student
r1.length=10;
r1.width=3;
System.out.println(“Length:”+ r1.length);
System.out.println(“Width:”+ r1.width);
}}
Output:
Length:10
width:3

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy