Chapter 11 (Constructors & Destructors) Flashcards
A method that has the same name as a class AND that establishes an object.
constructor method
A method that establishes an object
constructor method
True or False: A default constructor that is automatically created takes an argument
False, a default constructor requires no arguments.
A non-default or _________ constructor is one which requires arguments.
Parameterized
An automatically-created _______ _________ exists in a class in which the programmer has not explicitly written any _________.
default constructor, constructors
Does the automatically-supplied constructor provide initial values for the object’s data fields.
Only in some programming languages.
True or False: Any constructor the programmer writes must have the same name as the class in which it is defined?
True
True or False: You can create constructors for a class with or without parameters?
True
Once a programmer writes a constructor, regardless of whether the parameters were included, the automatically-supplied _______ constructor no longer ______.
default, exists
Three types of constructors:
- Default (parameterless)
- Default (parameterless) that is created _________.
- A _________ constructor with one or more _________ that must be _______ created.
explicitly, nondefault, parameters, explicitly
Can multiple explicitly-created nondefault constructors co-exist?
Yes
True or False: You can write any statement you want in a constructor, including calling other methods, accepting inputs, declaring local variables, etc.
True
A method’s ________ includes its name and list of argument types.
signature
True or False: All default constructors are created automatically.
False
_________ constructors only works if all the constructors have different signatures.
Overloading
The most common way to declare a destructor explicitly is to use an identifier that consists of a _____.
tilde / ~
True or False: A class can contain objects of another class as data fields.
True
Contains the actions you require when an instance of a class is destroyed.
Destructor
An instance of a class is destroyed when the object…
goes out of scope.
True or False: Destructors have parameters.
False
True or False: You can overload destructors.
False, a given class can only have ONE destructor
True or False: Destructors have to be explicitly written.
False, destructors are invoked automatically.
Destructors operate similar to a ____, in that the last object created is the first object destroyed.
cache
When an object is declared with a method, the object goes out of scope when the method _____.
ends
True or False: An instance of a class becomes eligible for destruction when it is no longer possible for any code to use it.
True
This is when a class contains objects, or “has an” instance, of another class (often as data fields)
Whole-part relationship
What is another phrase for a whole-part relationship?
“Composition”