Chapter 11 (Constructors & Destructors) Flashcards

1
Q

A method that has the same name as a class AND that establishes an object.

A

constructor method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A method that establishes an object

A

constructor method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

True or False: A default constructor that is automatically created takes an argument

A

False, a default constructor requires no arguments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A non-default or _________ constructor is one which requires arguments.

A

Parameterized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

An automatically-created _______ _________ exists in a class in which the programmer has not explicitly written any _________.

A

default constructor, constructors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Does the automatically-supplied constructor provide initial values for the object’s data fields.

A

Only in some programming languages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

True or False: Any constructor the programmer writes must have the same name as the class in which it is defined?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True or False: You can create constructors for a class with or without parameters?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Once a programmer writes a constructor, regardless of whether the parameters were included, the automatically-supplied _______ constructor no longer ______.

A

default, exists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Three types of constructors:

  1. Default (parameterless)
  2. Default (parameterless) that is created _________.
  3. A _________ constructor with one or more _________ that must be _______ created.
A

explicitly, nondefault, parameters, explicitly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Can multiple explicitly-created nondefault constructors co-exist?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

True or False: You can write any statement you want in a constructor, including calling other methods, accepting inputs, declaring local variables, etc.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A method’s ________ includes its name and list of argument types.

A

signature

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

True or False: All default constructors are created automatically.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

_________ constructors only works if all the constructors have different signatures.

A

Overloading

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The most common way to declare a destructor explicitly is to use an identifier that consists of a _____.

A

tilde / ~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

True or False: A class can contain objects of another class as data fields.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Contains the actions you require when an instance of a class is destroyed.

A

Destructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

An instance of a class is destroyed when the object…

A

goes out of scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

True or False: Destructors have parameters.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

True or False: You can overload destructors.

A

False, a given class can only have ONE destructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

True or False: Destructors have to be explicitly written.

A

False, destructors are invoked automatically.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Destructors operate similar to a ____, in that the last object created is the first object destroyed.

A

cache

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

When an object is declared with a method, the object goes out of scope when the method _____.

A

ends

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
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
26
This is when a class contains objects, or "has an" instance, of another class (often as data fields)
Whole-part relationship
27
What is another phrase for a whole-part relationship?
"Composition"
28
Deconstructors do not have _________.
parameters
29
A class that is used as a basis for inheritance
Base class
30
When the parts cease to exist as a result of the whole ceasing to exist.
Composition
31
When the parts can exist without the whole
Aggregation
32
One of the best parts of inheritance is that a programmer can reuse a class with fields and methods that have already been _______ and ______.
written, tested
33
Inheritance ______ _____ of errors, makes classes easier to _________, and makes the overall code easier to _______.
reduces chance, understand, maintain
34
A base class is the same as a _____ class and ________.
parent, superclass
35
These are classes that inherit from the base class.
derived class, extended class, subclass, child class
36
The entire list of parent classes from which a child class is derived.
Ancestors (of a subclass)
37
_______ classes often contain more fields and methods than ______ classes.
child, parent
38
Child classes are often more ________ than parent classes.
specialized
39
True or False: When a data field within a class is private, no outside class can use it - including any child classes.
True.
40
The _______ of a child class cannot directly access the data fields it inherits.
methods
41
How can you get around child class' methods not having direct access to data fields inherited from their parent class?
protected access specifiers
42
What symbol is used for the protected access specifier?
Octothorpe / #
43
True or False: The child class can use a public method within the parent class that modifies the field, just as any other outside class would.
True
44
This describes classes that depend on field names from parent classes.
Fragile
45
True or False: Classes that depend on field names from parent classes are prone to error.
True
46
When a subclass can inherit from more than one parent class, this is called...
multiple inheritance
47
The mechanism by which a child class method is used by default when a parent class contains a method with the same signature.
Overriding
48
Collections of classes that serve related purposes
Libraries
49
An environment in which you can create programs by dragging components such as buttons and labels onto a screen and arranging them visually.
Visual development environment
50
Exceptions is short for...
"exceptions to the rule"
51
A group of techniques for handling errors.
Exception handling
52
What is another word for libraries?
"Packages"
53
When you receive an exception the same way a parameter is received by a method
"catch the exception"
54
A block of code you attempt to execute while acknowledging that an exception might occur.
Try block
55
In pseudocode, you use _______ to end try blocks.
"endtry"
56
This sends an Exception object out of the current code block/method so that it can be handled elsewhere.
throw statement
57
A segment of code written to handle an exception that might be thrown by the try block that precedes it.
Catch block
58
A throw statement always leads to a ______ ____.
catch block
59
True or False: A catch block can catch all types of exceptions
False. Each catch block catches one type of exception that it handles, and the caught object must be of the type Exception or one of its child classes.
60
It is good programming to make an Exception _____.
Class
61
catch() is similar to a method, as it takes an ________ that is some type of _________. However, it is NOT a method.
argument, Exception
62
Why is catch() NOT a method?
1. It has no return type (this includes a void return type). | 2. You cannot call catch() directly.
63
Any _______ wherein there is high potentiality to throw an exception should be written within a ____ _____.
method, try block
64
The try and catch blocks work together as a...
"try...catch pair"
65
The common situation in which nothing goes wrong is referred to programmers, sardonically, as the...
sunny day case
66
Using a try...catch pair and developing an Exception class is a way of avoiding unfriendly _____ ________.
error messages
67
What is another phrase for a "whole part relationship"?
"has-a relationship"
68
A visual development environment is similar, if not often identical, to...
an IDE (Integrated Development Environment)