SlideShare a Scribd company logo
1 of 62
Java Programming: From Problem Analysis to Program Design, 4e Chapter 8 User-Defined Classes and ADTs
Chapter Objectives ,[object Object],[object Object],[object Object],[object Object]
Chapter Objectives (continued) ,[object Object],[object Object],[object Object]
Classes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Classes (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Classes (continued) ,[object Object],[object Object],[object Object],[object Object]
Syntax The general syntax for defining a class is:
Syntax (continued) ,[object Object],[object Object],[object Object]
Syntax (continued) ,[object Object],[object Object]
class  Clock : ,[object Object],[object Object],[object Object],[object Object]
class  Clock :  (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Constructors ,[object Object],[object Object],[object Object]
Constructors (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
class  Clock : Constructors ,[object Object],[object Object],[object Object],[object Object]
Unified Modeling Language Class Diagrams
Variable Declaration and Object Instantiation  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Variable Declaration and Object Instantiation (continued)
Variable Declaration and Object Instantiation (continued)
Accessing Class Members ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object]
Assignment Operator: A Precaution (continued)
Definitions of the Constructors and Methods of the  class  Clock
Definitions of the Constructors and Methods of the  class  Clock (continued)
Definitions of the Constructors and Methods of the  class  Clock (continued)
Definitions of the Constructors and Methods of the  class  Clock (continued)
Definitions of the Constructors and Methods of the  class  Clock (continued)
Definitions of the Constructors and Methods of the  class  Clock (continued)
Definitions of the Constructors and Methods of the  class  Clock (continued)
Definitions of the Constructors and Methods of the  class  Clock (continued)
Definitions of the Constructors and Methods of the  class  Clock (continued)
Definitions of the Constructors and Methods of the  class  Clock (continued)
Definitions of the Constructors and Methods of the  class  Clock (continued)
Definitions of the Constructors and Methods of the  class  Clock (continued)
Default Constructor or
Constructor with Parameters or
[object Object],[object Object],[object Object],[object Object],[object Object],The Method  toString
Method  toString :  class  Clock
The Copy Constructor ,[object Object],[object Object],[object Object]
The Copy Constructor (continued)
The Modifier  static ,[object Object],[object Object],[object Object],[object Object]
Static Members of a Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Static Members of a Class (continued) void  setX( int  a) { x = a; } public String  toString() { return ("x = " + x + ", y = " + y + ", count = " + count); } public static void  incrementY() { y++; } } Illustrate illusObject =  new  Illustrate(); Illustrate.incrementY(); Illustrate.count++;
Static Members of a Class (continued) Illustrate illusObject1 =  new  Illustrate(3);  Illustrate illusObject2 =  new  Illustrate(5);
Static Members of a Class (continued) Illustrate.incrementY(); Illustrate.count++;
Finalizers ,[object Object],[object Object],[object Object],[object Object]
Accessor and Mutator Methods ,[object Object],[object Object]
The Reference  this ,[object Object],[object Object]
Inner Classes ,[object Object],[object Object],[object Object]
Abstract Data Types ,[object Object],[object Object]
Programming Example: Candy Machine (Problem Statement) ,[object Object],[object Object],[object Object],[object Object],[object Object]
Programming Example: Candy Machine (Problem Statement) (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Programming Example: Candy Machine (Input and Output) ,[object Object],[object Object]
Programming Example:  Candy Machine ,[object Object],[object Object],[object Object],[object Object]
Programming Example:  Candy Machine (continued)
Programming Example:  Candy Machine (continued)
Programming Example:  Candy Machine (continued)
Programming Example:  Candy Machine (continued)
Programming Example:  Candy Machine (continued)
Programming Example:  Candy Machine (continued)
Chapter Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Chapter Summary (continued) ,[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introductionSohanur63
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in javaAtul Sehdev
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applicationskjkleindorfer
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classesFajar Baskoro
 
Week10 packages using objects in objects
Week10 packages using objects in objectsWeek10 packages using objects in objects
Week10 packages using objects in objectskjkleindorfer
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object ReferencesTareq Hasan
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesSunil Kumar Gunasekaran
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword pptVinod Kumar
 
Class & Object - Intro
Class & Object - IntroClass & Object - Intro
Class & Object - IntroPRN USM
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in javakamal kotecha
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritanceKalai Selvi
 

What's hot (20)

Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
4 Classes & Objects
4 Classes & Objects4 Classes & Objects
4 Classes & Objects
 
Class or Object
Class or ObjectClass or Object
Class or Object
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applications
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
 
Object and class
Object and classObject and class
Object and class
 
Week10 packages using objects in objects
Week10 packages using objects in objectsWeek10 packages using objects in objects
Week10 packages using objects in objects
 
C++ And Object in lecture3
C++  And Object in lecture3C++  And Object in lecture3
C++ And Object in lecture3
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object References
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examples
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword ppt
 
Ch03
Ch03Ch03
Ch03
 
Class & Object - Intro
Class & Object - IntroClass & Object - Intro
Class & Object - Intro
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritance
 
C++ classes
C++ classesC++ classes
C++ classes
 

Viewers also liked

9789740332930
97897403329309789740332930
9789740332930CUPress
 
980921大漢溪高灘地建設利用與管理–局
980921大漢溪高灘地建設利用與管理–局980921大漢溪高灘地建設利用與管理–局
980921大漢溪高灘地建設利用與管理–局yichin
 
제9장교육평가과제전망 김주찬
제9장교육평가과제전망 김주찬제9장교육평가과제전망 김주찬
제9장교육평가과제전망 김주찬Ju Chan Kim
 
98游泳成績
98游泳成績98游泳成績
98游泳成績rainlan
 
99 140624013641-phpapp01 2
99 140624013641-phpapp01 299 140624013641-phpapp01 2
99 140624013641-phpapp01 2Usama Waly
 
989078gnju76hjunhjunhjyunhjyunhjyuhjumhjujyu7
989078gnju76hjunhjunhjyunhjyunhjyuhjumhjujyu7989078gnju76hjunhjunhjyunhjyunhjyuhjumhjujyu7
989078gnju76hjunhjunhjyunhjyunhjyuhjumhjujyu7anthonyhenderson55
 
97029 incident report
97029   incident report97029   incident report
97029 incident reportJessica Saba
 
Кулінарія. Готуємо налисники. 9 клас
Кулінарія. Готуємо налисники. 9 класКулінарія. Готуємо налисники. 9 клас
Кулінарія. Готуємо налисники. 9 класAndy Levkovich
 
碩士班課程規劃表 97學年度入學學生適用
碩士班課程規劃表 97學年度入學學生適用碩士班課程規劃表 97學年度入學學生適用
碩士班課程規劃表 97學年度入學學生適用bububu2237
 

Viewers also liked (15)

96sdsdsds
96sdsdsds96sdsdsds
96sdsdsds
 
9789740332930
97897403329309789740332930
9789740332930
 
980921大漢溪高灘地建設利用與管理–局
980921大漢溪高灘地建設利用與管理–局980921大漢溪高灘地建設利用與管理–局
980921大漢溪高灘地建設利用與管理–局
 
9 565-8016cqd
9 565-8016cqd9 565-8016cqd
9 565-8016cqd
 
9707 s14 qp_33
9707 s14 qp_339707 s14 qp_33
9707 s14 qp_33
 
제9장교육평가과제전망 김주찬
제9장교육평가과제전망 김주찬제9장교육평가과제전망 김주찬
제9장교육평가과제전망 김주찬
 
9693128
96931289693128
9693128
 
98I8697444
98I869744498I8697444
98I8697444
 
98游泳成績
98游泳成績98游泳成績
98游泳成績
 
99 140624013641-phpapp01 2
99 140624013641-phpapp01 299 140624013641-phpapp01 2
99 140624013641-phpapp01 2
 
989078gnju76hjunhjunhjyunhjyunhjyuhjumhjujyu7
989078gnju76hjunhjunhjyunhjyunhjyuhjumhjujyu7989078gnju76hjunhjunhjyunhjyunhjyuhjumhjujyu7
989078gnju76hjunhjunhjyunhjyunhjyuhjumhjujyu7
 
97029 incident report
97029   incident report97029   incident report
97029 incident report
 
9707 w14 qp_11
9707 w14 qp_119707 w14 qp_11
9707 w14 qp_11
 
Кулінарія. Готуємо налисники. 9 клас
Кулінарія. Готуємо налисники. 9 класКулінарія. Готуємо налисники. 9 клас
Кулінарія. Готуємо налисники. 9 клас
 
碩士班課程規劃表 97學年度入學學生適用
碩士班課程規劃表 97學年度入學學生適用碩士班課程規劃表 97學年度入學學生適用
碩士班課程規劃表 97學年度入學學生適用
 

Similar to 9781439035665 ppt ch08

Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0BG Java EE Course
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slotsmha4
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slotsmha4
 
Object oriented design
Object oriented designObject oriented design
Object oriented designlykado0dles
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ Dev Chauhan
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesSakkaravarthiS1
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Abou Bakr Ashraf
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_typesAbed Bukhari
 
CJP Unit-1 contd.pptx
CJP Unit-1 contd.pptxCJP Unit-1 contd.pptx
CJP Unit-1 contd.pptxRAJASEKHARV10
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIEduardo Bergavera
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7Vince Vo
 

Similar to 9781439035665 ppt ch08 (20)

Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
Hemajava
HemajavaHemajava
Hemajava
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
Lec4
Lec4Lec4
Lec4
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
Object oriented design
Object oriented designObject oriented design
Object oriented design
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
 
oops-1
oops-1oops-1
oops-1
 
Unit i
Unit iUnit i
Unit i
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
 
Computer programming 2 Lesson 15
Computer programming 2  Lesson 15Computer programming 2  Lesson 15
Computer programming 2 Lesson 15
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_types
 
CJP Unit-1 contd.pptx
CJP Unit-1 contd.pptxCJP Unit-1 contd.pptx
CJP Unit-1 contd.pptx
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part II
 
Java Reflection
Java ReflectionJava Reflection
Java Reflection
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7
 

More from Terry Yoast

9781305078444 ppt ch12
9781305078444 ppt ch129781305078444 ppt ch12
9781305078444 ppt ch12Terry Yoast
 
9781305078444 ppt ch11
9781305078444 ppt ch119781305078444 ppt ch11
9781305078444 ppt ch11Terry Yoast
 
9781305078444 ppt ch10
9781305078444 ppt ch109781305078444 ppt ch10
9781305078444 ppt ch10Terry Yoast
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09Terry Yoast
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08Terry Yoast
 
9781305078444 ppt ch07
9781305078444 ppt ch079781305078444 ppt ch07
9781305078444 ppt ch07Terry Yoast
 
9781305078444 ppt ch06
9781305078444 ppt ch069781305078444 ppt ch06
9781305078444 ppt ch06Terry Yoast
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05Terry Yoast
 
9781305078444 ppt ch04
9781305078444 ppt ch049781305078444 ppt ch04
9781305078444 ppt ch04Terry Yoast
 
9781305078444 ppt ch03
9781305078444 ppt ch039781305078444 ppt ch03
9781305078444 ppt ch03Terry Yoast
 
9781305078444 ppt ch02
9781305078444 ppt ch029781305078444 ppt ch02
9781305078444 ppt ch02Terry Yoast
 
9781305078444 ppt ch01
9781305078444 ppt ch019781305078444 ppt ch01
9781305078444 ppt ch01Terry Yoast
 
9781337102087 ppt ch13
9781337102087 ppt ch139781337102087 ppt ch13
9781337102087 ppt ch13Terry Yoast
 
9781337102087 ppt ch18
9781337102087 ppt ch189781337102087 ppt ch18
9781337102087 ppt ch18Terry Yoast
 
9781337102087 ppt ch17
9781337102087 ppt ch179781337102087 ppt ch17
9781337102087 ppt ch17Terry Yoast
 
9781337102087 ppt ch16
9781337102087 ppt ch169781337102087 ppt ch16
9781337102087 ppt ch16Terry Yoast
 
9781337102087 ppt ch15
9781337102087 ppt ch159781337102087 ppt ch15
9781337102087 ppt ch15Terry Yoast
 
9781337102087 ppt ch14
9781337102087 ppt ch149781337102087 ppt ch14
9781337102087 ppt ch14Terry Yoast
 
9781337102087 ppt ch12
9781337102087 ppt ch129781337102087 ppt ch12
9781337102087 ppt ch12Terry Yoast
 
9781337102087 ppt ch11
9781337102087 ppt ch119781337102087 ppt ch11
9781337102087 ppt ch11Terry Yoast
 

More from Terry Yoast (20)

9781305078444 ppt ch12
9781305078444 ppt ch129781305078444 ppt ch12
9781305078444 ppt ch12
 
9781305078444 ppt ch11
9781305078444 ppt ch119781305078444 ppt ch11
9781305078444 ppt ch11
 
9781305078444 ppt ch10
9781305078444 ppt ch109781305078444 ppt ch10
9781305078444 ppt ch10
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
 
9781305078444 ppt ch07
9781305078444 ppt ch079781305078444 ppt ch07
9781305078444 ppt ch07
 
9781305078444 ppt ch06
9781305078444 ppt ch069781305078444 ppt ch06
9781305078444 ppt ch06
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
 
9781305078444 ppt ch04
9781305078444 ppt ch049781305078444 ppt ch04
9781305078444 ppt ch04
 
9781305078444 ppt ch03
9781305078444 ppt ch039781305078444 ppt ch03
9781305078444 ppt ch03
 
9781305078444 ppt ch02
9781305078444 ppt ch029781305078444 ppt ch02
9781305078444 ppt ch02
 
9781305078444 ppt ch01
9781305078444 ppt ch019781305078444 ppt ch01
9781305078444 ppt ch01
 
9781337102087 ppt ch13
9781337102087 ppt ch139781337102087 ppt ch13
9781337102087 ppt ch13
 
9781337102087 ppt ch18
9781337102087 ppt ch189781337102087 ppt ch18
9781337102087 ppt ch18
 
9781337102087 ppt ch17
9781337102087 ppt ch179781337102087 ppt ch17
9781337102087 ppt ch17
 
9781337102087 ppt ch16
9781337102087 ppt ch169781337102087 ppt ch16
9781337102087 ppt ch16
 
9781337102087 ppt ch15
9781337102087 ppt ch159781337102087 ppt ch15
9781337102087 ppt ch15
 
9781337102087 ppt ch14
9781337102087 ppt ch149781337102087 ppt ch14
9781337102087 ppt ch14
 
9781337102087 ppt ch12
9781337102087 ppt ch129781337102087 ppt ch12
9781337102087 ppt ch12
 
9781337102087 ppt ch11
9781337102087 ppt ch119781337102087 ppt ch11
9781337102087 ppt ch11
 

9781439035665 ppt ch08