SlideShare a Scribd company logo
Lecture – 4
Class and Object in JAVA
Lecturer
Department of CSE
Daffodil International University
Contents
• Class and Object in Java
• UML notations for class
2
Class and Objects
3
Classes and Objects
• Classes and Objects are basic concepts of Object Oriented Programming
which revolve around the real life entities.
• Everything in OOP is associated with classes and objects.
• A Class is like an object constructor, or a "blueprint" for creating objects.
4
1. Class
• A class is a user defined blueprint or prototype from which objects are created.
• It represents the set of properties or methods that are common to all objects of one
type.
• A java class can contains:
⮚ Data member/variables
⮚Method
⮚Constructor
⮚Block of Statements
⮚Class or Interface
5
*** Syntax of Creating a Class
modifiers class ClassName{
//body of the class
}
6
***Class Names - For all class names the first letter should be in Upper Case.
Example: public class Box { }
public class MyBox { }
2. Object
• A class is a template or blueprint from which objects are created. So, an object is the
instance(result) of a class.
• Object Definitions:
⮚An object is a real-world entity.
⮚An object is a runtime entity.
⮚The object is an entity which has state and behavior.
⮚The object is an instance of a class.
7
***Syntax of Creating an Object
ClassName objectName = new default_Constructor();
8
***Object Names - For all object names the first letter should be in lower Case.
Example - 1
• Create a Box Class. Each box of this class will have height and width.
• Create one object of the Box Class and display the information.
9
Solution of Example - 1:
public class Box {
int height;
int width;
public static void main(String[] args) {
Box box1 = new Box();
box1.height = 10;
box1.width = 20;
System.out.println("nHeight of box1 = " + box1.height);
System.out.println("Width of box1 = " + box1.width);
}
}
10
Example - 2
• Create a Person Class. Each person of this class will have name and age.
• Create two objects of the Person Class, Set the values and display the
information.
11
UML: Unified Modeling Language
UML Representation of CLASS
ClassName
Instance Variables
Methods
UML representation of Class from Example - 1
Box
height: int
width: int
+ main(String[]) : void
13
Example – 3: Write a Java code from this UML
Student
- name: String
- id: int
+ main(String[]) : void
14
• Create two objects of the Student Class, Set the values and display the information.
Solution of Example - 3:
public class Student {
private String name;
private int id;
private double cgpa;
public static void main(String[] args)
{
Student std1 = new Student();
std1.name = "Abdullah";
std1.id = 100;
std1.cgpa = 3.5;
System.out.println("Name of Student -1 : "+std1.name);
System.out.println("ID of Student - 1 : "+std1.id);
System.out.println("CGPA of Student - 1: "+std1.cgpa); 15
Student std2 = new Student();
std2.name = "Kabir";
std2.id = 200;
std2.cgpa = 3.8;
System.out.println("nnName of Student -1 : "+std2.name);
System.out.println("ID of Student - 1 : "+std2.id);
System.out.println("CGPA of Student - 1: "+std2.cgpa);
}
}
Example – 4: Write a Java code from this UML
Department
- deptName: String
- deptCode: int
- faculty: String
+ main(String[]) : void
16
• Create two objects of the Department Class, Set the values and display the information.
Thank you!
17

More Related Content

Similar to Lecture_4-Class and Object.pptx

IPP-M5-C1-Classes _ Objects python -S2.pptx
IPP-M5-C1-Classes _ Objects python -S2.pptxIPP-M5-C1-Classes _ Objects python -S2.pptx
IPP-M5-C1-Classes _ Objects python -S2.pptx
DhavalaShreeBJain
 
unit 2 java.pptx
unit 2 java.pptxunit 2 java.pptx
unit 2 java.pptx
AshokKumar587867
 
oop 3.pptx
oop 3.pptxoop 3.pptx
oop 3.pptx
OsamaMuhammad18
 
My Object Oriented.pptx
My Object Oriented.pptxMy Object Oriented.pptx
My Object Oriented.pptx
GopalNarayan7
 
Ch 2 Library Classes.pdf
Ch 2 Library Classes.pdfCh 2 Library Classes.pdf
Ch 2 Library Classes.pdf
KavitaHegde4
 
Ch 2 Library Classes.pptx
Ch 2 Library Classes.pptxCh 2 Library Classes.pptx
Ch 2 Library Classes.pptx
KavitaHegde4
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
Atul Sehdev
 
Object-Oriented Programming with C#
Object-Oriented Programming with C#Object-Oriented Programming with C#
Object-Oriented Programming with C#
Svetlin Nakov
 
BCA Class and Object (3).pptx
BCA Class and Object (3).pptxBCA Class and Object (3).pptx
BCA Class and Object (3).pptx
SarthakSrivastava70
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
Dennis Chang
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
Getachew Ganfur
 
Introduce oop in python
Introduce oop in pythonIntroduce oop in python
Introduce oop in python
tuan vo
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
ssuser8347a1
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
Danairat Thanabodithammachari
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++
Abdullah Jan
 
Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programming
shinyduela
 
Java chapter 4
Java chapter 4Java chapter 4
Java chapter 4
Abdii Rashid
 
OOP Presentation.pptx
OOP Presentation.pptxOOP Presentation.pptx
OOP Presentation.pptx
DurgaPrasadVasantati
 
OOP Presentation.pptx
OOP Presentation.pptxOOP Presentation.pptx
OOP Presentation.pptx
DurgaPrasadVasantati
 

Similar to Lecture_4-Class and Object.pptx (20)

IPP-M5-C1-Classes _ Objects python -S2.pptx
IPP-M5-C1-Classes _ Objects python -S2.pptxIPP-M5-C1-Classes _ Objects python -S2.pptx
IPP-M5-C1-Classes _ Objects python -S2.pptx
 
unit 2 java.pptx
unit 2 java.pptxunit 2 java.pptx
unit 2 java.pptx
 
oop 3.pptx
oop 3.pptxoop 3.pptx
oop 3.pptx
 
My Object Oriented.pptx
My Object Oriented.pptxMy Object Oriented.pptx
My Object Oriented.pptx
 
Ch 2 Library Classes.pdf
Ch 2 Library Classes.pdfCh 2 Library Classes.pdf
Ch 2 Library Classes.pdf
 
Ch 2 Library Classes.pptx
Ch 2 Library Classes.pptxCh 2 Library Classes.pptx
Ch 2 Library Classes.pptx
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
Object-Oriented Programming with C#
Object-Oriented Programming with C#Object-Oriented Programming with C#
Object-Oriented Programming with C#
 
BCA Class and Object (3).pptx
BCA Class and Object (3).pptxBCA Class and Object (3).pptx
BCA Class and Object (3).pptx
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
 
Introduce oop in python
Introduce oop in pythonIntroduce oop in python
Introduce oop in python
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++
 
Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programming
 
Java chapter 4
Java chapter 4Java chapter 4
Java chapter 4
 
OOP Presentation.pptx
OOP Presentation.pptxOOP Presentation.pptx
OOP Presentation.pptx
 
OOP Presentation.pptx
OOP Presentation.pptxOOP Presentation.pptx
OOP Presentation.pptx
 

More from ShahinAhmed49

BDBO Presentation.pptx
BDBO Presentation.pptxBDBO Presentation.pptx
BDBO Presentation.pptx
ShahinAhmed49
 
Lecture_7-Encapsulation in Java.pptx
Lecture_7-Encapsulation in Java.pptxLecture_7-Encapsulation in Java.pptx
Lecture_7-Encapsulation in Java.pptx
ShahinAhmed49
 
presentationonanalogtransmission-210806163622.pptx
presentationonanalogtransmission-210806163622.pptxpresentationonanalogtransmission-210806163622.pptx
presentationonanalogtransmission-210806163622.pptx
ShahinAhmed49
 
Presentation-10.pptx
Presentation-10.pptxPresentation-10.pptx
Presentation-10.pptx
ShahinAhmed49
 
Lecture_9-UML Basics_Inheritance_Association, Aggregation, Composition.pptx
Lecture_9-UML Basics_Inheritance_Association, Aggregation, Composition.pptxLecture_9-UML Basics_Inheritance_Association, Aggregation, Composition.pptx
Lecture_9-UML Basics_Inheritance_Association, Aggregation, Composition.pptx
ShahinAhmed49
 
presentationonanalogtransmission-210806163622.pptx
presentationonanalogtransmission-210806163622.pptxpresentationonanalogtransmission-210806163622.pptx
presentationonanalogtransmission-210806163622.pptx
ShahinAhmed49
 
Data (2).pptx
Data (2).pptxData (2).pptx
Data (2).pptx
ShahinAhmed49
 
Lecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptxLecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptx
ShahinAhmed49
 
Sentence Fragments(AA).pptx
Sentence Fragments(AA).pptxSentence Fragments(AA).pptx
Sentence Fragments(AA).pptx
ShahinAhmed49
 

More from ShahinAhmed49 (9)

BDBO Presentation.pptx
BDBO Presentation.pptxBDBO Presentation.pptx
BDBO Presentation.pptx
 
Lecture_7-Encapsulation in Java.pptx
Lecture_7-Encapsulation in Java.pptxLecture_7-Encapsulation in Java.pptx
Lecture_7-Encapsulation in Java.pptx
 
presentationonanalogtransmission-210806163622.pptx
presentationonanalogtransmission-210806163622.pptxpresentationonanalogtransmission-210806163622.pptx
presentationonanalogtransmission-210806163622.pptx
 
Presentation-10.pptx
Presentation-10.pptxPresentation-10.pptx
Presentation-10.pptx
 
Lecture_9-UML Basics_Inheritance_Association, Aggregation, Composition.pptx
Lecture_9-UML Basics_Inheritance_Association, Aggregation, Composition.pptxLecture_9-UML Basics_Inheritance_Association, Aggregation, Composition.pptx
Lecture_9-UML Basics_Inheritance_Association, Aggregation, Composition.pptx
 
presentationonanalogtransmission-210806163622.pptx
presentationonanalogtransmission-210806163622.pptxpresentationonanalogtransmission-210806163622.pptx
presentationonanalogtransmission-210806163622.pptx
 
Data (2).pptx
Data (2).pptxData (2).pptx
Data (2).pptx
 
Lecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptxLecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptx
 
Sentence Fragments(AA).pptx
Sentence Fragments(AA).pptxSentence Fragments(AA).pptx
Sentence Fragments(AA).pptx
 

Recently uploaded

Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 

Recently uploaded (20)

Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 

Lecture_4-Class and Object.pptx

  • 1. Lecture – 4 Class and Object in JAVA Lecturer Department of CSE Daffodil International University
  • 2. Contents • Class and Object in Java • UML notations for class 2
  • 4. Classes and Objects • Classes and Objects are basic concepts of Object Oriented Programming which revolve around the real life entities. • Everything in OOP is associated with classes and objects. • A Class is like an object constructor, or a "blueprint" for creating objects. 4
  • 5. 1. Class • A class is a user defined blueprint or prototype from which objects are created. • It represents the set of properties or methods that are common to all objects of one type. • A java class can contains: ⮚ Data member/variables ⮚Method ⮚Constructor ⮚Block of Statements ⮚Class or Interface 5
  • 6. *** Syntax of Creating a Class modifiers class ClassName{ //body of the class } 6 ***Class Names - For all class names the first letter should be in Upper Case. Example: public class Box { } public class MyBox { }
  • 7. 2. Object • A class is a template or blueprint from which objects are created. So, an object is the instance(result) of a class. • Object Definitions: ⮚An object is a real-world entity. ⮚An object is a runtime entity. ⮚The object is an entity which has state and behavior. ⮚The object is an instance of a class. 7
  • 8. ***Syntax of Creating an Object ClassName objectName = new default_Constructor(); 8 ***Object Names - For all object names the first letter should be in lower Case.
  • 9. Example - 1 • Create a Box Class. Each box of this class will have height and width. • Create one object of the Box Class and display the information. 9
  • 10. Solution of Example - 1: public class Box { int height; int width; public static void main(String[] args) { Box box1 = new Box(); box1.height = 10; box1.width = 20; System.out.println("nHeight of box1 = " + box1.height); System.out.println("Width of box1 = " + box1.width); } } 10
  • 11. Example - 2 • Create a Person Class. Each person of this class will have name and age. • Create two objects of the Person Class, Set the values and display the information. 11
  • 12. UML: Unified Modeling Language UML Representation of CLASS ClassName Instance Variables Methods
  • 13. UML representation of Class from Example - 1 Box height: int width: int + main(String[]) : void 13
  • 14. Example – 3: Write a Java code from this UML Student - name: String - id: int + main(String[]) : void 14 • Create two objects of the Student Class, Set the values and display the information.
  • 15. Solution of Example - 3: public class Student { private String name; private int id; private double cgpa; public static void main(String[] args) { Student std1 = new Student(); std1.name = "Abdullah"; std1.id = 100; std1.cgpa = 3.5; System.out.println("Name of Student -1 : "+std1.name); System.out.println("ID of Student - 1 : "+std1.id); System.out.println("CGPA of Student - 1: "+std1.cgpa); 15 Student std2 = new Student(); std2.name = "Kabir"; std2.id = 200; std2.cgpa = 3.8; System.out.println("nnName of Student -1 : "+std2.name); System.out.println("ID of Student - 1 : "+std2.id); System.out.println("CGPA of Student - 1: "+std2.cgpa); } }
  • 16. Example – 4: Write a Java code from this UML Department - deptName: String - deptCode: int - faculty: String + main(String[]) : void 16 • Create two objects of the Department Class, Set the values and display the information.