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

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

PPT
Overview of Object Oriented Programming using C++
jayanthi699330
 
PPTX
Object Oriented Programming_Lecture 2
Mahmoud Alfarra
 
PPTX
Java Inheritance - sub class constructors - Method overriding
NithyaN19
 
PPT
Classes and objects
Lovely Professional University
 
PPTX
Java chapter 5
Abdii Rashid
 
PPTX
Is2215 lecture2 student(2)
dannygriff1
 
PPTX
Nitish Chaulagai Java1.pptx
NitishChaulagai
 
PPT
Java lec class, objects and constructors
Jan Niño Acierto
 
PPTX
Oops
Jaya Kumari
 
PDF
Classes and Object Concept Object Oriented Programming in Java
gedeios
 
PDF
Lab 4 (1).pdf
MohammedAlobaidy16
 
PDF
Core Java Introduction | Basics
Hùng Nguyễn Huy
 
PPTX
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
DOCX
Object oriented basics
vamshimahi
 
PPTX
class and object in c++.pptx
Adarsh College, Hingoli
 
PPTX
Inner Classes & Multi Threading in JAVA
Tech_MX
 
PPTX
27csharp
Sireesh K
 
PPTX
27c
Sireesh K
 
PPTX
03 object-classes-pbl-4-slots
mha4
 
Overview of Object Oriented Programming using C++
jayanthi699330
 
Object Oriented Programming_Lecture 2
Mahmoud Alfarra
 
Java Inheritance - sub class constructors - Method overriding
NithyaN19
 
Classes and objects
Lovely Professional University
 
Java chapter 5
Abdii Rashid
 
Is2215 lecture2 student(2)
dannygriff1
 
Nitish Chaulagai Java1.pptx
NitishChaulagai
 
Java lec class, objects and constructors
Jan Niño Acierto
 
Classes and Object Concept Object Oriented Programming in Java
gedeios
 
Lab 4 (1).pdf
MohammedAlobaidy16
 
Core Java Introduction | Basics
Hùng Nguyễn Huy
 
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
Object oriented basics
vamshimahi
 
class and object in c++.pptx
Adarsh College, Hingoli
 
Inner Classes & Multi Threading in JAVA
Tech_MX
 
27csharp
Sireesh K
 
03 object-classes-pbl-4-slots
mha4
 

More from nandiaditi2010 (6)

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

Recently uploaded (20)

PPTX
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
PPTX
MODULE 04 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PDF
REINFORCEMENT LEARNING IN DECISION MAKING SEMINAR REPORT
anushaashraf20
 
PDF
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
PDF
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PPTX
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PDF
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PPTX
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PDF
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
PPTX
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
PPTX
Knowledge Representation : Semantic Networks
Amity University, Patna
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PPT
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
MODULE 04 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
REINFORCEMENT LEARNING IN DECISION MAKING SEMINAR REPORT
anushaashraf20
 
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
Knowledge Representation : Semantic Networks
Amity University, Patna
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
Ad

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