0% found this document useful (0 votes)
26 views

Console Class Constructors

This document discusses adding constructors to a Die class. It explains that constructors are used to create new objects of a class and pass information into the class. The Die class represents a die with properties for the number of sides and side currently on top, and a behavior to roll the die. Constructors can be used to create standard 6-sided dice or dice with any number of sides by passing parameters into the constructor header and call.

Uploaded by

Luca Kab
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Console Class Constructors

This document discusses adding constructors to a Die class. It explains that constructors are used to create new objects of a class and pass information into the class. The Die class represents a die with properties for the number of sides and side currently on top, and a behavior to roll the die. Constructors can be used to create standard 6-sided dice or dice with any number of sides by passing parameters into the constructor header and call.

Uploaded by

Luca Kab
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Module 11

Class Design and Implementation



Lecture
Console Class: Constructors

Module 11 Learning Objectives


Last time we designed our Die class and
implemented the fields and properties in the
class
This time, well add our constructors to the class




State, Behavior, and Identity
Identity
So we can distinguish one
object from another
Memory address
In-Lecture Quiz

To create a new object of a class (called instantiation)
we call the

A: police
B: cops
C: constructor
D: healer


Die Class
State: number of sides,
side thats on top
Behavior: roll
Identity: when we create a
new die object
(instantiation)
Standard 6-sided die
Die with any number of
sides (20, for example)
In-Lecture Quiz

When we want to pass information in to a constructor,
the constructor header needs to have

A: parameters
B: fuzzy feet
C: fancy fringe
D: party pickles
In-Lecture Quiz

When we want to pass information in to a constructor,
the call to the constructor needs to have

A: a cell phone
B: disagreements
C: fights
D: arguments


Recap
Weve added multiple constructors and learned
more about how parameters work
Next Time
Well add our Roll method to the Die class

You might also like