Beruflich Dokumente
Kultur Dokumente
and objects
1
Objectives
• Learn about class concepts
• How to create a class from which objects can
be instantiated
• Learn about instance variables and methods
• How to declare objects
2
Understanding Class Concepts
3
Understanding Class Concepts
4
Creating a Class from Which Objects Can
Be Instantiated
• A class header or class definition contains
three parts:
– An optional access modifier
– The keyword class
– Any legal identifier you choose for the name of your
class
5
Creating a Class from Which Objects Can
Be Instantiated
6
Creating Instance Variables and Methods
7
Creating Instance Variables and Methods
8
Creating Instance Variables and Methods
9
Creating Instance Variables and Methods
10
Declaring Objects
11
Declaring Objects
12
Compiling and Running a Program That
Instantiates Class Objects
• When you create an application that uses multiple class
definitions, the class definitions can be stored in either a
single file or each can be placed in its own file
• Storing all class definitions in one file shortens
development time and simplifies the compilation process
• Using separate files for each class definition provides a
more organized and manageable technique, and it
allows for easier reusability
13
Organizing Your Classes
14
Organizing Your Classes
16
Using Public Fields and Private Methods
19
Understanding the this Reference
20
Understanding the this Reference
21
Understanding the this Reference
22
Understanding the this Reference
23
Understanding Constructor Methods
24
Passing Parameters to Constructors
25
Passing Parameters to Constructors
26
Overloading Constructors
27
Understanding Destructor Methods
28
Understanding Destructor Methods