SlideShare a Scribd company logo
LAB REPORT
CSE222: Object-Oriented Programming Lab
Topic: Class & Object
Submitted To
Shahriar Hossain Shanto (SHS)
Designation
Department of CSE, Daffodil International University
Submitted By
Student ID: 0242310005101263
Section: 64_K2
Student Name: Md Rakibul Hasan
Date of Assignment Submission: 22nd November 2024
01
Experiment No: 01 Mapping: CO1 and CO2
Experiment Name Class & Object
Experiment Details:
Class:
A class in Java is a blueprint or template used to create objects. It defines properties (attributes) and behaviors
(methods) that the objects of the class will have. Think of a class as a prototype for creating similar entities.
Real-World Example
Consider the concept of a Car. Every car shares attributes like brand, model, color, speed, and behaviors like
start, stop, and accelerate. The class car would define these attributes and behaviors.
Object:
An object is an instance of a class. It represents a specific entity with a state (attributes) and behavior
(methods). Objects are created using the new keyword in Java.
Real-World Example
A specific car, like a red Toyota Corolla, is an object of the class Car. This object will have specific values for
its attributes, like color: red, brand: Toyota, and model: Corolla, and can perform behaviors like start, and
accelerate.
Code:
//file Name : Main
class Car {
String brand;
String model;
String color;
int speed;
Car(String brand, String model, String color, int speed) {
this.brand = brand;
this.model = model;
this.color = color;
this.speed = speed;
}
void start() {
System.out.println(brand + " " + model + " is starting.");
}
void accelerate(int increment) {
speed += increment;
System.out.println(brand + " " + model + "Current speed: " + speed + "
km/h");
}
void stop() {
System.out.println(brand + " " + model + " has stopped.");
speed = 0;
}
}
public class Main {
public static void main(String[] args) {
Car car1 = new Car("Toyota", "Corolla", "Red", 0);
Car car2 = new Car("Tesla", "Model 3", "Blue", 0);
car1.start();
car1.accelerate(60);
car1.stop();
car2.start();
car2.accelerate(80);
car2.stop();
}
}
Obtained Output:
Toyota Corolla is starting.
Toyota Corolla Current speed: 60 km/h
Toyota Corolla has stopped.
Tesla Model 3 is starting.
Tesla Model 3Current speed: 80 km/h
Tesla Model 3 has stopped.
Desired
Output?
YES

More Related Content

Similar to Class And Object- Java Object Oriented Programming Lab Report (20)

Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
DevaKumari Vijay
 
IFI7184.DT lesson1- Programming languages
IFI7184.DT lesson1- Programming languagesIFI7184.DT lesson1- Programming languages
IFI7184.DT lesson1- Programming languages
Sónia
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
Madishetty Prathibha
 
Object Oriended Programming with Java
Object Oriended Programming with JavaObject Oriended Programming with Java
Object Oriended Programming with Java
Jakir Hossain
 
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
 
Chap2 class,objects
Chap2 class,objectsChap2 class,objects
Chap2 class,objects
raksharao
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
BG Java EE Course
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
Rakesh Madugula
 
A350103
A350103A350103
A350103
aijbm
 
01 Introduction to OOP codinggggggggggggggggggggggggggggggggg
01 Introduction to OOP codinggggggggggggggggggggggggggggggggg01 Introduction to OOP codinggggggggggggggggggggggggggggggggg
01 Introduction to OOP codinggggggggggggggggggggggggggggggggg
lokesh437798
 
Ch2
Ch2Ch2
Ch2
Collin Aviles
 
javaopps concepts
javaopps conceptsjavaopps concepts
javaopps concepts
Nikhil Agrawal
 
14. Java defining classes
14. Java defining classes14. Java defining classes
14. Java defining classes
Intro C# Book
 
Java oop concepts
Java oop conceptsJava oop concepts
Java oop concepts
Syeful Islam
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
talha ijaz
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
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
 
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
 
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyjChapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
berihun18
 
IFI7184.DT lesson1- Programming languages
IFI7184.DT lesson1- Programming languagesIFI7184.DT lesson1- Programming languages
IFI7184.DT lesson1- Programming languages
Sónia
 
Object Oriended Programming with Java
Object Oriended Programming with JavaObject Oriended Programming with Java
Object Oriended Programming with Java
Jakir Hossain
 
Java is an Object-Oriented Language
Java is an Object-Oriented LanguageJava is an Object-Oriented Language
Java is an Object-Oriented Language
ale8819
 
Chap2 class,objects
Chap2 class,objectsChap2 class,objects
Chap2 class,objects
raksharao
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
BG Java EE Course
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
Rakesh Madugula
 
A350103
A350103A350103
A350103
aijbm
 
01 Introduction to OOP codinggggggggggggggggggggggggggggggggg
01 Introduction to OOP codinggggggggggggggggggggggggggggggggg01 Introduction to OOP codinggggggggggggggggggggggggggggggggg
01 Introduction to OOP codinggggggggggggggggggggggggggggggggg
lokesh437798
 
14. Java defining classes
14. Java defining classes14. Java defining classes
14. Java defining classes
Intro C# Book
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
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
 
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
 
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyjChapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
berihun18
 

Recently uploaded (20)

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
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo SlidesOverview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 EmployeesOverview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive LearningSustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Chalukyas of Gujrat, Solanki Dynasty NEP.pptxChalukyas of Gujrat, Solanki Dynasty NEP.pptx
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Introduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdfIntroduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdf
TechSoup
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptxPEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
Arshad Shaikh
 
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
 
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdfABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
TechSoup
 
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
 
LDMMIA Spring Ending Guest Grad Student News
LDMMIA Spring Ending Guest Grad Student NewsLDMMIA Spring Ending Guest Grad Student News
LDMMIA Spring Ending Guest Grad Student News
LDM & Mia eStudios
 
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
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdfThe Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil DisobediencePaper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
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
 
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
 
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
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo SlidesOverview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 EmployeesOverview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive LearningSustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Introduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdfIntroduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdf
TechSoup
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptxPEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
Arshad Shaikh
 
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
 
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdfABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
TechSoup
 
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
 
LDMMIA Spring Ending Guest Grad Student News
LDMMIA Spring Ending Guest Grad Student NewsLDMMIA Spring Ending Guest Grad Student News
LDMMIA Spring Ending Guest Grad Student News
LDM & Mia eStudios
 
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
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdfThe Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil DisobediencePaper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
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
 
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
 
Ad

Class And Object- Java Object Oriented Programming Lab Report

  • 1. LAB REPORT CSE222: Object-Oriented Programming Lab Topic: Class & Object Submitted To Shahriar Hossain Shanto (SHS) Designation Department of CSE, Daffodil International University Submitted By Student ID: 0242310005101263 Section: 64_K2 Student Name: Md Rakibul Hasan Date of Assignment Submission: 22nd November 2024 01
  • 2. Experiment No: 01 Mapping: CO1 and CO2 Experiment Name Class & Object Experiment Details: Class: A class in Java is a blueprint or template used to create objects. It defines properties (attributes) and behaviors (methods) that the objects of the class will have. Think of a class as a prototype for creating similar entities. Real-World Example Consider the concept of a Car. Every car shares attributes like brand, model, color, speed, and behaviors like start, stop, and accelerate. The class car would define these attributes and behaviors. Object: An object is an instance of a class. It represents a specific entity with a state (attributes) and behavior (methods). Objects are created using the new keyword in Java. Real-World Example A specific car, like a red Toyota Corolla, is an object of the class Car. This object will have specific values for its attributes, like color: red, brand: Toyota, and model: Corolla, and can perform behaviors like start, and accelerate. Code: //file Name : Main class Car { String brand; String model; String color; int speed; Car(String brand, String model, String color, int speed) { this.brand = brand; this.model = model; this.color = color; this.speed = speed; }
  • 3. void start() { System.out.println(brand + " " + model + " is starting."); } void accelerate(int increment) { speed += increment; System.out.println(brand + " " + model + "Current speed: " + speed + " km/h"); } void stop() { System.out.println(brand + " " + model + " has stopped."); speed = 0; } } public class Main { public static void main(String[] args) { Car car1 = new Car("Toyota", "Corolla", "Red", 0); Car car2 = new Car("Tesla", "Model 3", "Blue", 0); car1.start(); car1.accelerate(60); car1.stop(); car2.start(); car2.accelerate(80); car2.stop(); } } Obtained Output: Toyota Corolla is starting. Toyota Corolla Current speed: 60 km/h Toyota Corolla has stopped. Tesla Model 3 is starting. Tesla Model 3Current speed: 80 km/h Tesla Model 3 has stopped. Desired Output? YES