SlideShare a Scribd company logo
Class and Object
What is class ?
• A class is like a blueprint or template used to create objects.
• It defines properties (attributes) and methods (functions).
Example:
1. class Car {
2. String color=‘Black’ ;
3. void drive() {
4. System.out.println("Car is driving");
5. }
6. }
What is Object ?
• An object is an entity that has a state and some behavior.
• State refers to the data or properties and Behavior refers to the actions or
methods
• An object is an instance of a class. An instance is just a real, working object
created from a class.
• Created using a new keyword.
Example:
1. public class Main {
2. public static void main(String[] args) {
3. // Object creation
4. Car C1 = new Car ();
5. // Reading the properties
6. System.out.println (C1.color); // Black
7. }
8. }
Car C1 = new Car ();
Object creation :
Type of object is
car
Variable name of
the object
New keyword tells
java to create a
new object
What type of
object is created ,
-that is car
Example : Blueprint of car.
Properties :
Model name
Color
Price
Functionalities :
Drive
Lock
Unlock
1. class Car {
2. // Properties
3. String model = "Hatchback";
4. String color = "Black";
5. int price = 900000;
6. // Methods
7. void drive() {
8. System.out.println("Zoom Zoom Zoom");
9. }
10. void lock() {
11. System.out.println("Car is now locked");
12. }
13. void unlock() {
14. System.out.println("Car is now unlocked");
15. }
16. }
17. public class Main {
18 . public static void main(String[] args) {
19. // Creating objects
20. Car c1 = new Car();
21. Car c2 = new Car();
22. // Reading the properties
23. System.out.println(c1.color); // Black
24. System.out.println(c1.model); // Hatchback
25. System.out.println(c1.price); // 900000
26. //Reading the methods
27. c1.drive(); //Zoom Zoom Zoom
28. c2.unlock(); // car is now unlocked
29. c1.lock() ; // car is now lock
30. }
31. }
Code:
Class Object
Class is the blueprint of an object. It is used to
create objects.
An object is an instance of the class.
No memory is allocated when a class is
declared.
Memory is allocated as soon as an object is
created.
A class is a group of similar objects.
An object is a real-world entity such as a
book, car, etc.
Class is a logical entity. An object is a physical entity.
A class can only be declared once.
Objects can be created many times as per the
requirement.
An example of class can be a car.
Objects of the class car can be BMW,
Mercedes, Ferrari, etc.
Difference Between Java Classes and Objects
The table below demonstrates the difference between classes and objects in Java:
Thank You

More Related Content

Similar to Class and Object in java core programming (20)

Java
JavaJava
Java
Shridhar Ramesh
 
Java Classes fact general wireless-19*5.pptx
Java Classes fact general wireless-19*5.pptxJava Classes fact general wireless-19*5.pptx
Java Classes fact general wireless-19*5.pptx
IbrahimMerzayiee
 
Class in Java, Declaring a Class, Declaring a Member in a Class.pdf
Class in Java, Declaring a Class, Declaring a Member in a Class.pdfClass in Java, Declaring a Class, Declaring a Member in a Class.pdf
Class in Java, Declaring a Class, Declaring a Member in a Class.pdf
nandiaditi2010
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
DevaKumari Vijay
 
CLASSES AND OBJECT SAMPLE use for discussion.pptx
CLASSES AND OBJECT SAMPLE use for discussion.pptxCLASSES AND OBJECT SAMPLE use for discussion.pptx
CLASSES AND OBJECT SAMPLE use for discussion.pptx
MattFlordeliza1
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
Lecture2.pdf
Lecture2.pdfLecture2.pdf
Lecture2.pdf
SakhilejasonMsibi
 
Class and Objects in object-oriented programming with Java
Class and Objects in object-oriented programming with JavaClass and Objects in object-oriented programming with Java
Class and Objects in object-oriented programming with Java
Ranjan Karunadipathi
 
classes-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptxclasses-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
Epsiba1
 
Introduction to OOPS in Python bsics-.pptx
Introduction to OOPS in Python bsics-.pptxIntroduction to OOPS in Python bsics-.pptx
Introduction to OOPS in Python bsics-.pptx
GauravYadav906294
 
Class And Object- Java Object Oriented Programming Lab Report
Class And Object- Java Object Oriented Programming Lab ReportClass And Object- Java Object Oriented Programming Lab Report
Class And Object- Java Object Oriented Programming Lab Report
Daffodil International University
 
CS8392-OOPS-Printed-Notes-All-Units.pdf for students
CS8392-OOPS-Printed-Notes-All-Units.pdf for studentsCS8392-OOPS-Printed-Notes-All-Units.pdf for students
CS8392-OOPS-Printed-Notes-All-Units.pdf for students
KaviShetty
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
Rakesh Madugula
 
java
javajava
java
jent46
 
Java is an Object-Oriented Language
Java is an Object-Oriented LanguageJava is an Object-Oriented Language
Java is an Object-Oriented Language
ale8819
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
Fajar Baskoro
 
Simple class and object examples in java
Simple class and object examples in javaSimple class and object examples in java
Simple class and object examples in java
Harish Gyanani
 
8. objects & classes
8. objects & classes8. objects & classes
8. objects & classes
M H Buddhika Ariyaratne
 
Classes and Object Concept Object Oriented Programming in Java
Classes and Object Concept Object Oriented Programming in JavaClasses and Object Concept Object Oriented Programming in Java
Classes and Object Concept Object Oriented Programming in Java
gedeios
 
Java Classes fact general wireless-19*5.pptx
Java Classes fact general wireless-19*5.pptxJava Classes fact general wireless-19*5.pptx
Java Classes fact general wireless-19*5.pptx
IbrahimMerzayiee
 
Class in Java, Declaring a Class, Declaring a Member in a Class.pdf
Class in Java, Declaring a Class, Declaring a Member in a Class.pdfClass in Java, Declaring a Class, Declaring a Member in a Class.pdf
Class in Java, Declaring a Class, Declaring a Member in a Class.pdf
nandiaditi2010
 
CLASSES AND OBJECT SAMPLE use for discussion.pptx
CLASSES AND OBJECT SAMPLE use for discussion.pptxCLASSES AND OBJECT SAMPLE use for discussion.pptx
CLASSES AND OBJECT SAMPLE use for discussion.pptx
MattFlordeliza1
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
Class and Objects in object-oriented programming with Java
Class and Objects in object-oriented programming with JavaClass and Objects in object-oriented programming with Java
Class and Objects in object-oriented programming with Java
Ranjan Karunadipathi
 
classes-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptxclasses-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
Epsiba1
 
Introduction to OOPS in Python bsics-.pptx
Introduction to OOPS in Python bsics-.pptxIntroduction to OOPS in Python bsics-.pptx
Introduction to OOPS in Python bsics-.pptx
GauravYadav906294
 
Class And Object- Java Object Oriented Programming Lab Report
Class And Object- Java Object Oriented Programming Lab ReportClass And Object- Java Object Oriented Programming Lab Report
Class And Object- Java Object Oriented Programming Lab Report
Daffodil International University
 
CS8392-OOPS-Printed-Notes-All-Units.pdf for students
CS8392-OOPS-Printed-Notes-All-Units.pdf for studentsCS8392-OOPS-Printed-Notes-All-Units.pdf for students
CS8392-OOPS-Printed-Notes-All-Units.pdf for students
KaviShetty
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
Rakesh Madugula
 
Java is an Object-Oriented Language
Java is an Object-Oriented LanguageJava is an Object-Oriented Language
Java is an Object-Oriented Language
ale8819
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
Fajar Baskoro
 
Simple class and object examples in java
Simple class and object examples in javaSimple class and object examples in java
Simple class and object examples in java
Harish Gyanani
 
Classes and Object Concept Object Oriented Programming in Java
Classes and Object Concept Object Oriented Programming in JavaClasses and Object Concept Object Oriented Programming in Java
Classes and Object Concept Object Oriented Programming in Java
gedeios
 

Recently uploaded (20)

Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Ad

Class and Object in java core programming

  • 2. What is class ? • A class is like a blueprint or template used to create objects. • It defines properties (attributes) and methods (functions). Example: 1. class Car { 2. String color=‘Black’ ; 3. void drive() { 4. System.out.println("Car is driving"); 5. } 6. }
  • 3. What is Object ? • An object is an entity that has a state and some behavior. • State refers to the data or properties and Behavior refers to the actions or methods • An object is an instance of a class. An instance is just a real, working object created from a class. • Created using a new keyword. Example: 1. public class Main { 2. public static void main(String[] args) { 3. // Object creation 4. Car C1 = new Car (); 5. // Reading the properties 6. System.out.println (C1.color); // Black 7. } 8. }
  • 4. Car C1 = new Car (); Object creation : Type of object is car Variable name of the object New keyword tells java to create a new object What type of object is created , -that is car
  • 5. Example : Blueprint of car. Properties : Model name Color Price Functionalities : Drive Lock Unlock
  • 6. 1. class Car { 2. // Properties 3. String model = "Hatchback"; 4. String color = "Black"; 5. int price = 900000; 6. // Methods 7. void drive() { 8. System.out.println("Zoom Zoom Zoom"); 9. } 10. void lock() { 11. System.out.println("Car is now locked"); 12. } 13. void unlock() { 14. System.out.println("Car is now unlocked"); 15. } 16. } 17. public class Main { 18 . public static void main(String[] args) { 19. // Creating objects 20. Car c1 = new Car(); 21. Car c2 = new Car(); 22. // Reading the properties 23. System.out.println(c1.color); // Black 24. System.out.println(c1.model); // Hatchback 25. System.out.println(c1.price); // 900000 26. //Reading the methods 27. c1.drive(); //Zoom Zoom Zoom 28. c2.unlock(); // car is now unlocked 29. c1.lock() ; // car is now lock 30. } 31. } Code:
  • 7. Class Object Class is the blueprint of an object. It is used to create objects. An object is an instance of the class. No memory is allocated when a class is declared. Memory is allocated as soon as an object is created. A class is a group of similar objects. An object is a real-world entity such as a book, car, etc. Class is a logical entity. An object is a physical entity. A class can only be declared once. Objects can be created many times as per the requirement. An example of class can be a car. Objects of the class car can be BMW, Mercedes, Ferrari, etc. Difference Between Java Classes and Objects The table below demonstrates the difference between classes and objects in Java: