SlideShare a Scribd company logo
1
In the name of Allah
Ghalib University
Computer Science Faculty
General Department
Advanced Java
Lecture Title
Lecture #3 Practical Work
Examples
Subject: Advanced Java
Instructor: Saddiqi
Date: Saturday, July 5, 2025
List of Contents
• At First Some Questions
• Classes for Objects
• Constructor
• Default value of data fields
• Visibility Modifiers.
• Class and Object
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 2
At First Some Questions
• Describe the relationship between an object and its defining class.
• How do you define a class?
• How do you create an object?
• Which operator is used to access a data field or invoke a method from
an object?
• What is an anonymous object?
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 3
Classes for Objects
Example #1
• Here is a program that defines the Circle class and uses it to create
objects.
• At first look at the UML diagram:
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 4
Cont.
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 5
Cont.
Example #2
• As another example, consider television sets.
• Each TV is an object with states (current channel, current volume
level, power on or off) and behaviors (change channels, adjust
volume, turn on/off).
• You can use a class to model TV sets.
• The UML diagram for the class is shown in Figure 9.6.
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 6
Cont.
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 7
Cont.
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 8
Cont.
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 9
Constructor
Example #3
• What is wrong in the
following code?
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 10
Default value of data fields
Example #4
• What is the output of
the following code?
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 11
Cont.
Example #5
• What is wrong with each of the following programs?
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 12
Visibility Modifiers.
Example #6
• In this code, radius is private
in the Circle class,
• and myCircle is an object of the
Circle class.
• Does the highlighted code cause
any problems? If so, explain
why.
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 13
Class and Object
Example #7
• (The Rectangle class) design a class named Rectangle to represent a
rectangle.
• The class contains:
1. Two double data fields named width and height that specify the width and height of the
rectangle. The default values are 1 for both width and height.
2. A no-arg constructor that creates a default rectangle.
3. A constructor that creates a rectangle with the specified width and height.
4. A method named getArea() that returns the area of this rectangle.
5. A method named getPerimeter() that returns the perimeter.
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 15
Summary
• At First Some Questions
• Classes for Objects
• Constructor
• Default value of data fields
• Visibility Modifiers.
• Class and Object
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 16
The End
Thank You
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 17

More Related Content

PPTX
Advanced Java - Lec #2 ~ Practical Work Examples.pptx
PPTX
Advanced Java - Lec #5 - Inheritance and Polymorphism.pptx
PPTX
CT077-3-2-Data Structures - 0 - Introduction and Module Overview (1).pptx
PDF
lecture1.pdf
PPT
Classroom for the_future
PPTX
Macro Analysis on how to Potentiate Experimental Competences Using VISIR
PPT
Project template
PPTX
Sewizg512 ooad cs01_introduction
Advanced Java - Lec #2 ~ Practical Work Examples.pptx
Advanced Java - Lec #5 - Inheritance and Polymorphism.pptx
CT077-3-2-Data Structures - 0 - Introduction and Module Overview (1).pptx
lecture1.pdf
Classroom for the_future
Macro Analysis on how to Potentiate Experimental Competences Using VISIR
Project template
Sewizg512 ooad cs01_introduction

Similar to Advanced Java - Lec #3 ~ Practical Work Examples.pptx (20)

PPTX
Wilczewski iced report to nasa at ksc on 20180609 f
PDF
Lecture 1 v3.pdf
PPTX
2CPP01 - Intro to Module
PPTX
RIU Content Preperation for notes Template.pptx
PPTX
Week 5 case analysis - rules and expectations
PDF
It 405 materi 1 pengantar
PDF
It 405 materi 1 pengantar
PPTX
It 405 materi 1 pengantar
PPTX
Activity of integration_Revised KAMURASI.pptx
PPTX
Formal Method
PPTX
Java parser a fine grained indexing tool and its application
PPTX
Moodle Analytic Admin Tool Plugin for Student Performance Predict
PPTX
William Eckert ADDIE vs Dick and Carey Model
PPTX
Importance of testing for the business
PDF
Fpfoyfoyfoydoyfoyf. Coycoyclyckyc. Kyclyckycpu. Lyckyckyc kg kg ky
PPTX
Acte 2015 certification magic
PPTX
The ADDIE model vs The Dick Carey Model
PPTX
surya session power point presentation.pptx
PPTX
Best Practices for Linked Data Education
PPTX
DT-G3-T1-W8-L3-Excel Extended .pptx
Wilczewski iced report to nasa at ksc on 20180609 f
Lecture 1 v3.pdf
2CPP01 - Intro to Module
RIU Content Preperation for notes Template.pptx
Week 5 case analysis - rules and expectations
It 405 materi 1 pengantar
It 405 materi 1 pengantar
It 405 materi 1 pengantar
Activity of integration_Revised KAMURASI.pptx
Formal Method
Java parser a fine grained indexing tool and its application
Moodle Analytic Admin Tool Plugin for Student Performance Predict
William Eckert ADDIE vs Dick and Carey Model
Importance of testing for the business
Fpfoyfoyfoydoyfoyf. Coycoyclyckyc. Kyclyckycpu. Lyckyckyc kg kg ky
Acte 2015 certification magic
The ADDIE model vs The Dick Carey Model
surya session power point presentation.pptx
Best Practices for Linked Data Education
DT-G3-T1-W8-L3-Excel Extended .pptx
Ad

Recently uploaded (20)

PDF
Visual explanation of Dijkstra's Algorithm using Python
PDF
Cost to Outsource Software Development in 2025
PDF
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PPTX
Cybersecurity: Protecting the Digital World
PDF
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
PPTX
GSA Content Generator Crack (2025 Latest)
PDF
DNT Brochure 2025 – ISV Solutions @ D365
PDF
Website Design Services for Small Businesses.pdf
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Microsoft Office 365 Crack Download Free
PPTX
assetexplorer- product-overview - presentation
PDF
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
PDF
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
PDF
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
PDF
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
PPTX
Tech Workshop Escape Room Tech Workshop
PPTX
Monitoring Stack: Grafana, Loki & Promtail
Visual explanation of Dijkstra's Algorithm using Python
Cost to Outsource Software Development in 2025
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Cybersecurity: Protecting the Digital World
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
GSA Content Generator Crack (2025 Latest)
DNT Brochure 2025 – ISV Solutions @ D365
Website Design Services for Small Businesses.pdf
Oracle Fusion HCM Cloud Demo for Beginners
CCleaner 6.39.11548 Crack 2025 License Key
Computer Software and OS of computer science of grade 11.pptx
Microsoft Office 365 Crack Download Free
assetexplorer- product-overview - presentation
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
Tech Workshop Escape Room Tech Workshop
Monitoring Stack: Grafana, Loki & Promtail
Ad

Advanced Java - Lec #3 ~ Practical Work Examples.pptx

  • 1. 1 In the name of Allah Ghalib University Computer Science Faculty General Department Advanced Java Lecture Title Lecture #3 Practical Work Examples Subject: Advanced Java Instructor: Saddiqi Date: Saturday, July 5, 2025
  • 2. List of Contents • At First Some Questions • Classes for Objects • Constructor • Default value of data fields • Visibility Modifiers. • Class and Object Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 2
  • 3. At First Some Questions • Describe the relationship between an object and its defining class. • How do you define a class? • How do you create an object? • Which operator is used to access a data field or invoke a method from an object? • What is an anonymous object? Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 3
  • 4. Classes for Objects Example #1 • Here is a program that defines the Circle class and uses it to create objects. • At first look at the UML diagram: Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 4
  • 5. Cont. Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 5
  • 6. Cont. Example #2 • As another example, consider television sets. • Each TV is an object with states (current channel, current volume level, power on or off) and behaviors (change channels, adjust volume, turn on/off). • You can use a class to model TV sets. • The UML diagram for the class is shown in Figure 9.6. Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 6
  • 7. Cont. Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 7
  • 8. Cont. Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 8
  • 9. Cont. Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 9
  • 10. Constructor Example #3 • What is wrong in the following code? Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 10
  • 11. Default value of data fields Example #4 • What is the output of the following code? Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 11
  • 12. Cont. Example #5 • What is wrong with each of the following programs? Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 12
  • 13. Visibility Modifiers. Example #6 • In this code, radius is private in the Circle class, • and myCircle is an object of the Circle class. • Does the highlighted code cause any problems? If so, explain why. Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 13
  • 14. Class and Object Example #7 • (The Rectangle class) design a class named Rectangle to represent a rectangle. • The class contains: 1. Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. 2. A no-arg constructor that creates a default rectangle. 3. A constructor that creates a rectangle with the specified width and height. 4. A method named getArea() that returns the area of this rectangle. 5. A method named getPerimeter() that returns the perimeter. Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 15
  • 15. Summary • At First Some Questions • Classes for Objects • Constructor • Default value of data fields • Visibility Modifiers. • Class and Object Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 16
  • 16. The End Thank You Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 17