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
Q

True or False: An instance of a class becomes eligible for destruction when it is no longer possible for any code to use it.

A

True

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

This is when a class contains objects, or “has an” instance, of another class (often as data fields)

A

Whole-part relationship

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

What is another phrase for a whole-part relationship?

A

“Composition”

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

Deconstructors do not have _________.

A

parameters

29
Q

A class that is used as a basis for inheritance

A

Base class

30
Q

When the parts cease to exist as a result of the whole ceasing to exist.

A

Composition

31
Q

When the parts can exist without the whole

A

Aggregation

32
Q

One of the best parts of inheritance is that a programmer can reuse a class with fields and methods that have already been _______ and ______.

A

written, tested

33
Q

Inheritance ______ _____ of errors, makes classes easier to _________, and makes the overall code easier to _______.

A

reduces chance, understand, maintain

34
Q

A base class is the same as a _____ class and ________.

A

parent, superclass

35
Q

These are classes that inherit from the base class.

A

derived class, extended class, subclass, child class

36
Q

The entire list of parent classes from which a child class is derived.

A

Ancestors (of a subclass)

37
Q

_______ classes often contain more fields and methods than ______ classes.

A

child, parent

38
Q

Child classes are often more ________ than parent classes.

A

specialized

39
Q

True or False: When a data field within a class is private, no outside class can use it - including any child classes.

A

True.

40
Q

The _______ of a child class cannot directly access the data fields it inherits.

A

methods

41
Q

How can you get around child class’ methods not having direct access to data fields inherited from their parent class?

A

protected access specifiers

42
Q

What symbol is used for the protected access specifier?

A

Octothorpe / #

43
Q

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.

A

True

44
Q

This describes classes that depend on field names from parent classes.

A

Fragile

45
Q

True or False: Classes that depend on field names from parent classes are prone to error.

A

True

46
Q

When a subclass can inherit from more than one parent class, this is called…

A

multiple inheritance

47
Q

The mechanism by which a child class method is used by default when a parent class contains a method with the same signature.

A

Overriding

48
Q

Collections of classes that serve related purposes

A

Libraries

49
Q

An environment in which you can create programs by dragging components such as buttons and labels onto a screen and arranging them visually.

A

Visual development environment

50
Q

Exceptions is short for…

A

“exceptions to the rule”

51
Q

A group of techniques for handling errors.

A

Exception handling

52
Q

What is another word for libraries?

A

“Packages”

53
Q

When you receive an exception the same way a parameter is received by a method

A

“catch the exception”

54
Q

A block of code you attempt to execute while acknowledging that an exception might occur.

A

Try block

55
Q

In pseudocode, you use _______ to end try blocks.

A

“endtry”

56
Q

This sends an Exception object out of the current code block/method so that it can be handled elsewhere.

A

throw statement

57
Q

A segment of code written to handle an exception that might be thrown by the try block that precedes it.

A

Catch block

58
Q

A throw statement always leads to a ______ ____.

A

catch block

59
Q

True or False: A catch block can catch all types of exceptions

A

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
Q

It is good programming to make an Exception _____.

A

Class

61
Q

catch() is similar to a method, as it takes an ________ that is some type of _________. However, it is NOT a method.

A

argument, Exception

62
Q

Why is catch() NOT a method?

A
  1. It has no return type (this includes a void return type).

2. You cannot call catch() directly.

63
Q

Any _______ wherein there is high potentiality to throw an exception should be written within a ____ _____.

A

method, try block

64
Q

The try and catch blocks work together as a…

A

“try…catch pair”

65
Q

The common situation in which nothing goes wrong is referred to programmers, sardonically, as the…

A

sunny day case

66
Q

Using a try…catch pair and developing an Exception class is a way of avoiding unfriendly _____ ________.

A

error messages

67
Q

What is another phrase for a “whole part relationship”?

A

“has-a relationship”

68
Q

A visual development environment is similar, if not often identical, to…

A

an IDE (Integrated Development Environment)