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

PPT
Unidad o informatica en ingles
PPTX
Ch-2ppt.pptx
PDF
Lecture2.pdf
PPTX
Class and Object in java core programming
PPTX
Object Oriented Programming concepts in JAVA
PPTX
Java Classes fact general wireless-19*5.pptx
PPTX
classes-objects in oops java-201023154255.pptx
PPT
Object Oriented Programming with Java
Unidad o informatica en ingles
Ch-2ppt.pptx
Lecture2.pdf
Class and Object in java core programming
Object Oriented Programming concepts in JAVA
Java Classes fact general wireless-19*5.pptx
classes-objects in oops java-201023154255.pptx
Object Oriented Programming with Java

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

PPTX
Unit3 part1-class
PPTX
IFI7184.DT lesson1- Programming languages
PPTX
Classes objects in java
PPTX
Object Oriended Programming with Java
PPT
java
PPT
Java is an Object-Oriented Language
PPTX
Chap2 class,objects
PPT
Defining classes-and-objects-1.0
PPT
Md02 - Getting Started part-2
PDF
A350103
PDF
01 Introduction to OOP codinggggggggggggggggggggggggggggggggg
DOCX
javaopps concepts
PPTX
14. Java defining classes
DOCX
Java oop concepts
PPTX
Lecture 4
PPTX
Android Training (Java Review)
PPTX
introduction to Object oriented programming in java.pptx
PPTX
Introduction to OOPS in Python bsics-.pptx
PDF
CS8392-OOPS-Printed-Notes-All-Units.pdf for students
Unit3 part1-class
IFI7184.DT lesson1- Programming languages
Classes objects in java
Object Oriended Programming with Java
java
Java is an Object-Oriented Language
Chap2 class,objects
Defining classes-and-objects-1.0
Md02 - Getting Started part-2
A350103
01 Introduction to OOP codinggggggggggggggggggggggggggggggggg
javaopps concepts
14. Java defining classes
Java oop concepts
Lecture 4
Android Training (Java Review)
introduction to Object oriented programming in java.pptx
Introduction to OOPS in Python bsics-.pptx
CS8392-OOPS-Printed-Notes-All-Units.pdf for students
Ad

Recently uploaded (20)

PDF
Complications of Minimal Access Surgery at WLH
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Institutional Correction lecture only . . .
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Lesson notes of climatology university.
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Complications of Minimal Access Surgery at WLH
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
01-Introduction-to-Information-Management.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Institutional Correction lecture only . . .
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Final Presentation General Medicine 03-08-2024.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Module 4: Burden of Disease Tutorial Slides S2 2025
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
GDM (1) (1).pptx small presentation for students
Microbial diseases, their pathogenesis and prophylaxis
Lesson notes of climatology university.
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
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