SlideShare a Scribd company logo
CLASS
CLASSES
A class is a collection of fields (data) and
methods (procedure or function) that
operate on that data.
Circle
centre
radius
circumference()
area()
 A Class is a template
 It provides a new data type
 It is logical entity , does not exist physically
OBJECT
 The variable of the new data type i.e class is Called object
 It is an instance of the class
 It exists physically i.e take space in memory
 To access the class object is necessary
SYNTAX TO DECLARE CLASS…
 class demo
{
}
 class demo2
{type instance var;
type maethod(parameter lists)
{
}
}
 public class Circle {
double x, y; // centre coordinate
double r; // radius of the circle
}
 The fields (data) are also called the instance varaibles.
 A class with only data fields has no life. Objects created by such a
class cannot respond to any messages.
 Methods are declared inside the body of the class but
immediately after the declaration of data fields.
 The general form of a method declaration is
type MethodName (parameter-list)
{
Method-body;
}
 public class Circle {
double x, y; // centre of the circle
double r; // radius of circle
//Methods to return circumference and area
public double circumference() {
return 2*3.14*r;
}
public double area() {
return 3.14 * r * r;
}
}
 Declare the Circle class, have created a new data type – Data
Abstraction
 Can define variables (objects) of that type:
Circle aCircle; // Variable of class
Circle bCircle;
aCircle, bCircle simply refers to a Circle object,
not an object itself.
null
11
CREATING OBJECTS OF A CLASS
 Objects are created dynamically using the new keyword.
 aCircle and bCircle refer to Circle objects
bCircle = new Circle() ;aCircle = new Circle() ;
 aCircle = new Circle();
 bCircle = new Circle() ;
 bCircle = aCircle;
13
CREATING OBJECTS OF A CLASS
aCircle = new Circle();
bCircle = new Circle() ;
bCircle = aCircle;
P
aCircle
Q
bCircle
Before Assignment
P
aCircle
Q
bCircle
After Assignment
14
ACCESSING OBJECT/CIRCLE DATA
 Similar to C syntax for accessing data defined in a structure.
Circle aCircle = new Circle();
aCircle.x = 2.0 // initialize center and radius
aCircle.y = 2.0
aCircle.r = 1.0
ObjectName.VariableName
ObjectName.MethodName(parameter-list)
15
EXECUTING METHODS IN
OBJECT/CIRCLE
 Using Object Methods:
Circle aCircle = new Circle();
double area;
aCircle.r = 1.0;
area = aCircle.area();
sent ‘message’ to aCircle

More Related Content

Similar to Java Classes (20)

PPT
Class and Object.ppt
Genta Sahuri
 
PPT
Unit 1 Part - 2 Class Object.ppt
DeepVala5
 
PPT
Lect 1-class and object
Fajar Baskoro
 
PDF
Lecture-03 _Java Classes_from FAST-NUCES
UzairSaeed18
 
PPT
Java Presentation.ppt
Morgan309846
 
PPT
Module 3 Class and Object.ppt
RanjithKumar742256
 
PPTX
Class and Object.pptx
Hailsh
 
PPT
Lecture 2 classes i
the_wumberlog
 
PPT
08slide
Dorothea Chaffin
 
PPT
JavaYDL8
Terry Yoast
 
PPT
Core Java unit no. 1 object and class ppt
Mochi263119
 
PPT
Oops concept in c#
ANURAG SINGH
 
PPT
Unit 1 Part - 3 constructor Overloading Static.ppt
DeepVala5
 
PPT
Chapter 9 Objects and Classes JAVA learning
AhsirYu
 
PPT
Object and class in java
Umamaheshwariv1
 
PPT
09_ Objects and Classes in programming.ppt
MajedAlAnesi
 
PPTX
Lab4-Software-Construction-BSSE5.pptx ppt
MuhammadAbubakar114879
 
PPT
slides 01.ppt
Anwar Ali Yahya
 
PPT
09slide.ppt
kavitamittal18
 
PPT
09slide.ppt oops classes and objects concept
kavitamittal18
 
Class and Object.ppt
Genta Sahuri
 
Unit 1 Part - 2 Class Object.ppt
DeepVala5
 
Lect 1-class and object
Fajar Baskoro
 
Lecture-03 _Java Classes_from FAST-NUCES
UzairSaeed18
 
Java Presentation.ppt
Morgan309846
 
Module 3 Class and Object.ppt
RanjithKumar742256
 
Class and Object.pptx
Hailsh
 
Lecture 2 classes i
the_wumberlog
 
JavaYDL8
Terry Yoast
 
Core Java unit no. 1 object and class ppt
Mochi263119
 
Oops concept in c#
ANURAG SINGH
 
Unit 1 Part - 3 constructor Overloading Static.ppt
DeepVala5
 
Chapter 9 Objects and Classes JAVA learning
AhsirYu
 
Object and class in java
Umamaheshwariv1
 
09_ Objects and Classes in programming.ppt
MajedAlAnesi
 
Lab4-Software-Construction-BSSE5.pptx ppt
MuhammadAbubakar114879
 
slides 01.ppt
Anwar Ali Yahya
 
09slide.ppt
kavitamittal18
 
09slide.ppt oops classes and objects concept
kavitamittal18
 

Recently uploaded (20)

PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
July Patch Tuesday
Ivanti
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Ad

Java Classes

  • 2. CLASSES A class is a collection of fields (data) and methods (procedure or function) that operate on that data. Circle centre radius circumference() area()
  • 3.  A Class is a template  It provides a new data type  It is logical entity , does not exist physically
  • 4. OBJECT  The variable of the new data type i.e class is Called object  It is an instance of the class  It exists physically i.e take space in memory  To access the class object is necessary
  • 5. SYNTAX TO DECLARE CLASS…  class demo { }  class demo2 {type instance var; type maethod(parameter lists) { } }
  • 6.  public class Circle { double x, y; // centre coordinate double r; // radius of the circle }  The fields (data) are also called the instance varaibles.
  • 7.  A class with only data fields has no life. Objects created by such a class cannot respond to any messages.  Methods are declared inside the body of the class but immediately after the declaration of data fields.  The general form of a method declaration is type MethodName (parameter-list) { Method-body; }
  • 8.  public class Circle { double x, y; // centre of the circle double r; // radius of circle //Methods to return circumference and area public double circumference() { return 2*3.14*r; } public double area() { return 3.14 * r * r; } }
  • 9.  Declare the Circle class, have created a new data type – Data Abstraction  Can define variables (objects) of that type: Circle aCircle; // Variable of class Circle bCircle;
  • 10. aCircle, bCircle simply refers to a Circle object, not an object itself. null
  • 11. 11 CREATING OBJECTS OF A CLASS  Objects are created dynamically using the new keyword.  aCircle and bCircle refer to Circle objects bCircle = new Circle() ;aCircle = new Circle() ;
  • 12.  aCircle = new Circle();  bCircle = new Circle() ;  bCircle = aCircle;
  • 13. 13 CREATING OBJECTS OF A CLASS aCircle = new Circle(); bCircle = new Circle() ; bCircle = aCircle; P aCircle Q bCircle Before Assignment P aCircle Q bCircle After Assignment
  • 14. 14 ACCESSING OBJECT/CIRCLE DATA  Similar to C syntax for accessing data defined in a structure. Circle aCircle = new Circle(); aCircle.x = 2.0 // initialize center and radius aCircle.y = 2.0 aCircle.r = 1.0 ObjectName.VariableName ObjectName.MethodName(parameter-list)
  • 15. 15 EXECUTING METHODS IN OBJECT/CIRCLE  Using Object Methods: Circle aCircle = new Circle(); double area; aCircle.r = 1.0; area = aCircle.area(); sent ‘message’ to aCircle