SlideShare a Scribd company logo
1
Class in Java, Declaring a Class,
Declaring a Member in a Class
Prepared By:
Aditi Nandi Tokder
Assistant Professor
ECE Department
Techno Main Salt Lake
Content
1. Topic Name 1
2. Introduction to Java Classes 3
3. Declaring a Class 4
4. Class Syntax 5
5. Defining Class Member 6
6. Accessing Class Member 7
7. Encapsulation and Information Hiding 8
8. Conclusion 9
9. Thank You 10
2
Introduction to 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
4
➢ A class is a blueprint in the Java programming language from which an individual object can be built. In Java, we
may declare a class by using the class keyword. Class members and functions are declared simply within the class.
Classes are required for the creation of Java programs. The object-oriented paradigm (OOP) allows users to
describe real-world objects. Also, a class is sometimes known as a user-defined data type. The following
components make up a class declaration:
Modifiers
Class name
Keywords
The class body within curly brackets {}.
•
•
•
•
➢ Syntax :-
public class ClassName {
// class body
}
• The ‘public’ keyword specifies that the class is accessible by any other class.
• The ‘class’ keyword is used to create a class.
• ‘ClassName’ is the name of the class.
Declaring a Class
Class Syntax
5
The syntax of
a class
declaration
includes the
class keyword,
the class
name, access
modifiers, and
the class body
containing
members.
Access
Modifiers
Control the
visibility of the
class and its
members
(e.g., public,
private).
Class Name
A unique
identifier that
follows Java
naming
conventions.
Class Body
Encloses the
class
members,
such as
variables and
methods.
Defining Class Member
6
Class members define the
attributes and actions
associated with objects
created from the class. They
can include instance
variables, methods, and
constructors. The system
allocates memory for a class
variable the first time it
encounters the class.
All instances of that
class share the same
copy of the class’s
class variables.
You can access class
variables either
through an instance or
through the class
itself.
Similarly, class
methods can be
invoked on the class
or through an instance
reference.
Note that when the
program changes the
value of classVariable
, its value changes for
all instance .
Instance Variables
Data fields that store
the state of an object.
Class Methods
Functions that define
the behavior of an
object.
Constructors
Special methods used
to initialize objects.
Accessing Class Member
7
Class members can be accessed using the dot (.) operator. The object's name followed by the dot
operator and the member name is used for accessing.
Instance Variables:-
Accessible within the class and through objects created from the class.
Syntax:-
ClassName objectName = new ClassName(parameters);
Example:-
Dog myDog = new Dog("Labrador", 3);
Explanation:-
‘mydog’ is an object of ‘Dog’ class.
Methods:-
Invoked using the object's name followed by the method name and arguments.
Accessing variables:-
myDog.breed;
myDog.age;
Calling methods:-
myDog.bark();
Encapsulation and Information Hiding
8
Encapsulation is a key
principle of object-
oriented programming
that combines data and
methods within a class. It
protects data from direct
access, enhancing code
maintainability and
security.
Data Hiding
Using the "private" access
modifier to restrict access
to instance variables from
outside the class.
Getters and Setters
Methods that provide
controlled access to
private data members.
Conclusion
9
In Java, a class is a blueprint for creating objects, encapsulating data and methods.
Declaring a class involves defining its structure, while declaring members includes
specifying variables and methods within the class. This fundamental concept
underpins Java's object-oriented programming, enabling organized, reusable, and
modular code.
10

More Related Content

PPTX
classes-objects in oops java-201023154255.pptx
PPTX
Ch-2ppt.pptx
PPTX
OOP with Java - Introducing Classes - Module-2.pptx
DOCX
javaopps concepts
PDF
JAVA PPT -2 BY ADI.pdf
PDF
Core Java Introduction | Basics
PPTX
Object oriented programming CLASSES-AND-OBJECTS.pptx
PPTX
Basic concept of Object Oriented Programming
classes-objects in oops java-201023154255.pptx
Ch-2ppt.pptx
OOP with Java - Introducing Classes - Module-2.pptx
javaopps concepts
JAVA PPT -2 BY ADI.pdf
Core Java Introduction | Basics
Object oriented programming CLASSES-AND-OBJECTS.pptx
Basic concept of Object Oriented Programming

Similar to Class in Java, Declaring a Class, Declaring a Member in a Class.pdf (20)

DOCX
Computer Programming 2
PPT
Core Java unit no. 1 object and class ppt
PPTX
class as the basis.pptx
PPTX
Chapter 7 java
PPTX
oop 3.pptx
PPT
Java lec class, objects and constructors
PPTX
Introduction to OOP with java
PPTX
Classes objects in java
PPT
Unidad o informatica en ingles
PDF
ITFT-Classes and object in java
PPTX
Android Training (Java Review)
PPTX
CLASSES AND OBJECT SAMPLE use for discussion.pptx
PPTX
Unit3 part1-class
PDF
Classes, objects, methods, constructors, this keyword in java
PPT
packages and interfaces
PDF
01 Introduction to OOP codinggggggggggggggggggggggggggggggggg
PDF
CS8392-OOPS-Printed-Notes-All-Units.pdf for students
PPTX
Module 4_Ch2 - Introduction to Object Oriented Programming.pptx
PPT
Java Presentation.ppt
PPTX
Object Oriented Programming concepts in JAVA
Computer Programming 2
Core Java unit no. 1 object and class ppt
class as the basis.pptx
Chapter 7 java
oop 3.pptx
Java lec class, objects and constructors
Introduction to OOP with java
Classes objects in java
Unidad o informatica en ingles
ITFT-Classes and object in java
Android Training (Java Review)
CLASSES AND OBJECT SAMPLE use for discussion.pptx
Unit3 part1-class
Classes, objects, methods, constructors, this keyword in java
packages and interfaces
01 Introduction to OOP codinggggggggggggggggggggggggggggggggg
CS8392-OOPS-Printed-Notes-All-Units.pdf for students
Module 4_Ch2 - Introduction to Object Oriented Programming.pptx
Java Presentation.ppt
Object Oriented Programming concepts in JAVA
Ad

More from nandiaditi2010 (6)

PDF
Graffiti 23_compressed .pdf
PDF
CSMA .pdf
PDF
PASS BY VALUE .pdf
PDF
Web Technology-Method .pdf
PDF
Networking Basics .pdf
PDF
IP Address & Its Classes .pdf
Graffiti 23_compressed .pdf
CSMA .pdf
PASS BY VALUE .pdf
Web Technology-Method .pdf
Networking Basics .pdf
IP Address & Its Classes .pdf
Ad

Recently uploaded (20)

PPTX
OOP with Java - Java Introduction (Basics)
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Geodesy 1.pptx...............................................
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Digital Logic Computer Design lecture notes
PPTX
web development for engineering and engineering
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Sustainable Sites - Green Building Construction
PDF
composite construction of structures.pdf
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Construction Project Organization Group 2.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Welding lecture in detail for understanding
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
OOP with Java - Java Introduction (Basics)
R24 SURVEYING LAB MANUAL for civil enggi
Geodesy 1.pptx...............................................
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Lecture Notes Electrical Wiring System Components
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Digital Logic Computer Design lecture notes
web development for engineering and engineering
bas. eng. economics group 4 presentation 1.pptx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Sustainable Sites - Green Building Construction
composite construction of structures.pdf
Embodied AI: Ushering in the Next Era of Intelligent Systems
Model Code of Practice - Construction Work - 21102022 .pdf
Construction Project Organization Group 2.pptx
Internet of Things (IOT) - A guide to understanding
Welding lecture in detail for understanding
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx

Class in Java, Declaring a Class, Declaring a Member in a Class.pdf

  • 1. 1 Class in Java, Declaring a Class, Declaring a Member in a Class Prepared By: Aditi Nandi Tokder Assistant Professor ECE Department Techno Main Salt Lake
  • 2. Content 1. Topic Name 1 2. Introduction to Java Classes 3 3. Declaring a Class 4 4. Class Syntax 5 5. Defining Class Member 6 6. Accessing Class Member 7 7. Encapsulation and Information Hiding 8 8. Conclusion 9 9. Thank You 10 2
  • 3. Introduction to 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
  • 4. 4 ➢ A class is a blueprint in the Java programming language from which an individual object can be built. In Java, we may declare a class by using the class keyword. Class members and functions are declared simply within the class. Classes are required for the creation of Java programs. The object-oriented paradigm (OOP) allows users to describe real-world objects. Also, a class is sometimes known as a user-defined data type. The following components make up a class declaration: Modifiers Class name Keywords The class body within curly brackets {}. • • • • ➢ Syntax :- public class ClassName { // class body } • The ‘public’ keyword specifies that the class is accessible by any other class. • The ‘class’ keyword is used to create a class. • ‘ClassName’ is the name of the class. Declaring a Class
  • 5. Class Syntax 5 The syntax of a class declaration includes the class keyword, the class name, access modifiers, and the class body containing members. Access Modifiers Control the visibility of the class and its members (e.g., public, private). Class Name A unique identifier that follows Java naming conventions. Class Body Encloses the class members, such as variables and methods.
  • 6. Defining Class Member 6 Class members define the attributes and actions associated with objects created from the class. They can include instance variables, methods, and constructors. The system allocates memory for a class variable the first time it encounters the class. All instances of that class share the same copy of the class’s class variables. You can access class variables either through an instance or through the class itself. Similarly, class methods can be invoked on the class or through an instance reference. Note that when the program changes the value of classVariable , its value changes for all instance . Instance Variables Data fields that store the state of an object. Class Methods Functions that define the behavior of an object. Constructors Special methods used to initialize objects.
  • 7. Accessing Class Member 7 Class members can be accessed using the dot (.) operator. The object's name followed by the dot operator and the member name is used for accessing. Instance Variables:- Accessible within the class and through objects created from the class. Syntax:- ClassName objectName = new ClassName(parameters); Example:- Dog myDog = new Dog("Labrador", 3); Explanation:- ‘mydog’ is an object of ‘Dog’ class. Methods:- Invoked using the object's name followed by the method name and arguments. Accessing variables:- myDog.breed; myDog.age; Calling methods:- myDog.bark();
  • 8. Encapsulation and Information Hiding 8 Encapsulation is a key principle of object- oriented programming that combines data and methods within a class. It protects data from direct access, enhancing code maintainability and security. Data Hiding Using the "private" access modifier to restrict access to instance variables from outside the class. Getters and Setters Methods that provide controlled access to private data members.
  • 9. Conclusion 9 In Java, a class is a blueprint for creating objects, encapsulating data and methods. Declaring a class involves defining its structure, while declaring members includes specifying variables and methods within the class. This fundamental concept underpins Java's object-oriented programming, enabling organized, reusable, and modular code.
  • 10. 10