Deck 9: Using Classes and Objects

Full screen (f)
exit full mode
Question
The ____ class access modifier means that access is limited to another class to which the class belongs.

A) private
B) internal
C) protected
D) public
Use Space or
up arrow
down arrow
to flip the card.
Question
Instance variables are often called ____ to help distinguish them from other variables you might use.

A) states
B) relationships
C) instantiations
D) fields
Question
The ____ class access modifier means that access is limited to the assembly (a group of code modules compiled together) to which the class belongs.

A) private
B) internal
C) protected
D) public
Question
When you create an array of objects, the array holds the actual value of each of the objects.
Question
The ____ class access modifier means that access to the class is not limited.

A) protected
B) private
C) internal
D) public
Question
The data components of a class that differ for each object are stored in ____.

A) instance variables
B) states
C) instantiations
D) relationships
Question
A(n) ____ parameter is one that is undeclared and that gets its value automatically.

A) implicit
B) explicit
C) instance
D) property
Question
If you do not provide an access specifier for a class field, its access is ____ by default.

A) public
B) internal
C) private
D) protected
Question
Properties have ____ that specify the statements that execute when a class's fields are accessed.

A) instance variables
B) fields
C) operators
D) accessors
Question
A class that instantiates objects of another prewritten class is known as a class client or class ____.

A) state
B) instantiation
C) user
D) server
Question
Using private fields within classes is an example of ____, a feature found in all object-oriented languages.

A) information hiding
B) polymorphism
C) inheritance
D) overloading
Question
Only nonstatic methods receive a this reference.
Question
Predefined types such as int , double , and char are ____ types.

A) reference
B) value
C) output
D) pointer
Question
A(n) ____ constructor will never take any parameters.

A) object
B) default
C) initializer
D) array
Question
The ____ class access modifier means that access to the class is limited to the class and to any classes derived from the class.

A) internal
B) private
C) protected
D) public
Question
The set of contents of an object's instance variables also is known as its ____.

A) relationship
B) state
C) instantiation
D) field
Question
An implicit, or invisible, ____ reference is passed to every instance method and property accessor.

A) static
B) object
C) use
D) this
Question
If you don't write a constructor for a class object, C# writes one for you.
Question
You can overload an operator for a built-in data type. For example, you can change the meaning of + between two int s.
Question
A GUI object, such as a Button , is represented as an object that cannot encapsulate any methods.
Question
What is the difference between overriding a method and overloading a method with respect to method signatures?
Question
The Sort() method accepts an array as a parameter and arranges its elements in descending order. What complication arises when you sort an array of objects? Explain how to use the IComparable interface to address this problem.
Question
As an alternative to repeating code in multiple constructors, a ____ indicates that another instance of a class constructor should be executed before any statements in the current constructor body.

A) parameterless constructor
B) value constructor
C) constructor initializer
D) default constructor
Question
When a method ____ another, it takes precedence over the method, hiding the original version.

A) instantiates
B) overrides
C) overloads
D) extends
Question
Briefly explain how to create instance variables, and show how to define a private integer instance variable called idNumber within a class called Employee .
Question
Classes that support simple data items each contain a method named ____, which provides the details of how items in the class compare to each other.

A) Equals()
B) Less()
C) IndexOf()
D) CompareTo()
Question
What are the three parts of a class definition in C#?
Question
Like any other C# method, constructors can be overloaded. Show how to create two public constructors-one with no parameters, and one with a parameter called sal -that both set the value for the property Salary within the following class:
class Employee
{
public double Salary;
}
Question
What are the class access modifiers in C#?
Question
A(n) ____ is a collection of abstract methods (and perhaps other members) that can be used by any class, as long as the class overrides the abstract method definitions.

A) multifile assembly
B) framework
C) interface
D) destructor
Question
Methods associated with objects are called ____________________.
Question
A ____ contains the actions you require when an instance of a class is destroyed-for example, when the instance goes out of scope.

A) constructor
B) constructor initializer
C) destructor
D) parameterless constructor
Question
Briefly describe what an object initializer does and give a specific example. When is the object initializer assignment made?
Question
A(n) ____________________ is a member of a class that provides access to a field of a class.
Question
Properties contain ____________________ for setting an object's fields.
Question
Creating an object requires two steps that are shown in the example below:
Employee myAssistant;
myAssistant = new Employee();
What do these statements accomplish?
Question
C# contains a(n) ____ interface, which contains the definition for the CompareTo() method that compares one object to another and returns an integer.

A) IComparable
B) Comparable
C) ICompareTo
D) CompareTo
Question
An object is a(n) ____________________ (tangible example) of a class.
Question
Write an example method that overrides the + operator to create a new book whose title is a concatenation of the titles of two books. For example, if the first book's title is "The Adventures of Tom Sawyer" and the second book's title is "The Adventures of Huckleberry Finn", the concatenated title will be "The Adventures of Tom Sawyer and The Adventures of Huckleberry Finn".  Assume the book class is defined as:
class Book
{
public Book( string title)
{
Title = title;
}
public string Title {get; set;}
}
Question
A(n) ____________________ is a method that instantiates (creates an instance of) an object.
Question
Match between columns
A definition containing an optional access modifier, the keyword class , and an identifier
reference type
A definition containing an optional access modifier, the keyword class , and an identifier
get accessor
A definition containing an optional access modifier, the keyword class , and an identifier
constructor initializer
A definition containing an optional access modifier, the keyword class , and an identifier
default constructor
A definition containing an optional access modifier, the keyword class , and an identifier
set accessor
A definition containing an optional access modifier, the keyword class , and an identifier
default value
A definition containing an optional access modifier, the keyword class , and an identifier
contextual keywords
A definition containing an optional access modifier, the keyword class , and an identifier
class client
A definition containing an optional access modifier, the keyword class , and an identifier
class header
The value of an object initialized with a default constructor
reference type
The value of an object initialized with a default constructor
get accessor
The value of an object initialized with a default constructor
constructor initializer
The value of an object initialized with a default constructor
default constructor
The value of an object initialized with a default constructor
set accessor
The value of an object initialized with a default constructor
default value
The value of an object initialized with a default constructor
contextual keywords
The value of an object initialized with a default constructor
class client
The value of an object initialized with a default constructor
class header
Sets an object's fields
reference type
Sets an object's fields
get accessor
Sets an object's fields
constructor initializer
Sets an object's fields
default constructor
Sets an object's fields
set accessor
Sets an object's fields
default value
Sets an object's fields
contextual keywords
Sets an object's fields
class client
Sets an object's fields
class header
Retrieves an object's field values
reference type
Retrieves an object's field values
get accessor
Retrieves an object's field values
constructor initializer
Retrieves an object's field values
default constructor
Retrieves an object's field values
set accessor
Retrieves an object's field values
default value
Retrieves an object's field values
contextual keywords
Retrieves an object's field values
class client
Retrieves an object's field values
class header
An automatically generated constructor for a class
reference type
An automatically generated constructor for a class
get accessor
An automatically generated constructor for a class
constructor initializer
An automatically generated constructor for a class
default constructor
An automatically generated constructor for a class
set accessor
An automatically generated constructor for a class
default value
An automatically generated constructor for a class
contextual keywords
An automatically generated constructor for a class
class client
An automatically generated constructor for a class
class header
Identifiers that act like keywords in specific circumstances
reference type
Identifiers that act like keywords in specific circumstances
get accessor
Identifiers that act like keywords in specific circumstances
constructor initializer
Identifiers that act like keywords in specific circumstances
default constructor
Identifiers that act like keywords in specific circumstances
set accessor
Identifiers that act like keywords in specific circumstances
default value
Identifiers that act like keywords in specific circumstances
contextual keywords
Identifiers that act like keywords in specific circumstances
class client
Identifiers that act like keywords in specific circumstances
class header
A type that refers to a specific memory location
reference type
A type that refers to a specific memory location
get accessor
A type that refers to a specific memory location
constructor initializer
A type that refers to a specific memory location
default constructor
A type that refers to a specific memory location
set accessor
A type that refers to a specific memory location
default value
A type that refers to a specific memory location
contextual keywords
A type that refers to a specific memory location
class client
A type that refers to a specific memory location
class header
A program or class that instantiates objects of another prewritten class
reference type
A program or class that instantiates objects of another prewritten class
get accessor
A program or class that instantiates objects of another prewritten class
constructor initializer
A program or class that instantiates objects of another prewritten class
default constructor
A program or class that instantiates objects of another prewritten class
set accessor
A program or class that instantiates objects of another prewritten class
default value
A program or class that instantiates objects of another prewritten class
contextual keywords
A program or class that instantiates objects of another prewritten class
class client
A program or class that instantiates objects of another prewritten class
class header
An alternative to repeating code in the constructors
reference type
An alternative to repeating code in the constructors
get accessor
An alternative to repeating code in the constructors
constructor initializer
An alternative to repeating code in the constructors
default constructor
An alternative to repeating code in the constructors
set accessor
An alternative to repeating code in the constructors
default value
An alternative to repeating code in the constructors
contextual keywords
An alternative to repeating code in the constructors
class client
An alternative to repeating code in the constructors
class header
Question
Explain what a destructor is and why it cannot be overloaded.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/42
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 9: Using Classes and Objects
1
The ____ class access modifier means that access is limited to another class to which the class belongs.

A) private
B) internal
C) protected
D) public
A
2
Instance variables are often called ____ to help distinguish them from other variables you might use.

A) states
B) relationships
C) instantiations
D) fields
D
3
The ____ class access modifier means that access is limited to the assembly (a group of code modules compiled together) to which the class belongs.

A) private
B) internal
C) protected
D) public
B
4
When you create an array of objects, the array holds the actual value of each of the objects.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
5
The ____ class access modifier means that access to the class is not limited.

A) protected
B) private
C) internal
D) public
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
6
The data components of a class that differ for each object are stored in ____.

A) instance variables
B) states
C) instantiations
D) relationships
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
7
A(n) ____ parameter is one that is undeclared and that gets its value automatically.

A) implicit
B) explicit
C) instance
D) property
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
8
If you do not provide an access specifier for a class field, its access is ____ by default.

A) public
B) internal
C) private
D) protected
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
9
Properties have ____ that specify the statements that execute when a class's fields are accessed.

A) instance variables
B) fields
C) operators
D) accessors
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
10
A class that instantiates objects of another prewritten class is known as a class client or class ____.

A) state
B) instantiation
C) user
D) server
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
11
Using private fields within classes is an example of ____, a feature found in all object-oriented languages.

A) information hiding
B) polymorphism
C) inheritance
D) overloading
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
12
Only nonstatic methods receive a this reference.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
13
Predefined types such as int , double , and char are ____ types.

A) reference
B) value
C) output
D) pointer
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
14
A(n) ____ constructor will never take any parameters.

A) object
B) default
C) initializer
D) array
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
15
The ____ class access modifier means that access to the class is limited to the class and to any classes derived from the class.

A) internal
B) private
C) protected
D) public
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
16
The set of contents of an object's instance variables also is known as its ____.

A) relationship
B) state
C) instantiation
D) field
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
17
An implicit, or invisible, ____ reference is passed to every instance method and property accessor.

A) static
B) object
C) use
D) this
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
18
If you don't write a constructor for a class object, C# writes one for you.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
19
You can overload an operator for a built-in data type. For example, you can change the meaning of + between two int s.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
20
A GUI object, such as a Button , is represented as an object that cannot encapsulate any methods.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
21
What is the difference between overriding a method and overloading a method with respect to method signatures?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
22
The Sort() method accepts an array as a parameter and arranges its elements in descending order. What complication arises when you sort an array of objects? Explain how to use the IComparable interface to address this problem.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
23
As an alternative to repeating code in multiple constructors, a ____ indicates that another instance of a class constructor should be executed before any statements in the current constructor body.

A) parameterless constructor
B) value constructor
C) constructor initializer
D) default constructor
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
24
When a method ____ another, it takes precedence over the method, hiding the original version.

A) instantiates
B) overrides
C) overloads
D) extends
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
25
Briefly explain how to create instance variables, and show how to define a private integer instance variable called idNumber within a class called Employee .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
26
Classes that support simple data items each contain a method named ____, which provides the details of how items in the class compare to each other.

A) Equals()
B) Less()
C) IndexOf()
D) CompareTo()
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
27
What are the three parts of a class definition in C#?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
28
Like any other C# method, constructors can be overloaded. Show how to create two public constructors-one with no parameters, and one with a parameter called sal -that both set the value for the property Salary within the following class:
class Employee
{
public double Salary;
}
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
29
What are the class access modifiers in C#?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
30
A(n) ____ is a collection of abstract methods (and perhaps other members) that can be used by any class, as long as the class overrides the abstract method definitions.

A) multifile assembly
B) framework
C) interface
D) destructor
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
31
Methods associated with objects are called ____________________.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
32
A ____ contains the actions you require when an instance of a class is destroyed-for example, when the instance goes out of scope.

A) constructor
B) constructor initializer
C) destructor
D) parameterless constructor
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
33
Briefly describe what an object initializer does and give a specific example. When is the object initializer assignment made?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
34
A(n) ____________________ is a member of a class that provides access to a field of a class.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
35
Properties contain ____________________ for setting an object's fields.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
36
Creating an object requires two steps that are shown in the example below:
Employee myAssistant;
myAssistant = new Employee();
What do these statements accomplish?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
37
C# contains a(n) ____ interface, which contains the definition for the CompareTo() method that compares one object to another and returns an integer.

A) IComparable
B) Comparable
C) ICompareTo
D) CompareTo
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
38
An object is a(n) ____________________ (tangible example) of a class.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
39
Write an example method that overrides the + operator to create a new book whose title is a concatenation of the titles of two books. For example, if the first book's title is "The Adventures of Tom Sawyer" and the second book's title is "The Adventures of Huckleberry Finn", the concatenated title will be "The Adventures of Tom Sawyer and The Adventures of Huckleberry Finn".  Assume the book class is defined as:
class Book
{
public Book( string title)
{
Title = title;
}
public string Title {get; set;}
}
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
40
A(n) ____________________ is a method that instantiates (creates an instance of) an object.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
41
Match between columns
A definition containing an optional access modifier, the keyword class , and an identifier
reference type
A definition containing an optional access modifier, the keyword class , and an identifier
get accessor
A definition containing an optional access modifier, the keyword class , and an identifier
constructor initializer
A definition containing an optional access modifier, the keyword class , and an identifier
default constructor
A definition containing an optional access modifier, the keyword class , and an identifier
set accessor
A definition containing an optional access modifier, the keyword class , and an identifier
default value
A definition containing an optional access modifier, the keyword class , and an identifier
contextual keywords
A definition containing an optional access modifier, the keyword class , and an identifier
class client
A definition containing an optional access modifier, the keyword class , and an identifier
class header
The value of an object initialized with a default constructor
reference type
The value of an object initialized with a default constructor
get accessor
The value of an object initialized with a default constructor
constructor initializer
The value of an object initialized with a default constructor
default constructor
The value of an object initialized with a default constructor
set accessor
The value of an object initialized with a default constructor
default value
The value of an object initialized with a default constructor
contextual keywords
The value of an object initialized with a default constructor
class client
The value of an object initialized with a default constructor
class header
Sets an object's fields
reference type
Sets an object's fields
get accessor
Sets an object's fields
constructor initializer
Sets an object's fields
default constructor
Sets an object's fields
set accessor
Sets an object's fields
default value
Sets an object's fields
contextual keywords
Sets an object's fields
class client
Sets an object's fields
class header
Retrieves an object's field values
reference type
Retrieves an object's field values
get accessor
Retrieves an object's field values
constructor initializer
Retrieves an object's field values
default constructor
Retrieves an object's field values
set accessor
Retrieves an object's field values
default value
Retrieves an object's field values
contextual keywords
Retrieves an object's field values
class client
Retrieves an object's field values
class header
An automatically generated constructor for a class
reference type
An automatically generated constructor for a class
get accessor
An automatically generated constructor for a class
constructor initializer
An automatically generated constructor for a class
default constructor
An automatically generated constructor for a class
set accessor
An automatically generated constructor for a class
default value
An automatically generated constructor for a class
contextual keywords
An automatically generated constructor for a class
class client
An automatically generated constructor for a class
class header
Identifiers that act like keywords in specific circumstances
reference type
Identifiers that act like keywords in specific circumstances
get accessor
Identifiers that act like keywords in specific circumstances
constructor initializer
Identifiers that act like keywords in specific circumstances
default constructor
Identifiers that act like keywords in specific circumstances
set accessor
Identifiers that act like keywords in specific circumstances
default value
Identifiers that act like keywords in specific circumstances
contextual keywords
Identifiers that act like keywords in specific circumstances
class client
Identifiers that act like keywords in specific circumstances
class header
A type that refers to a specific memory location
reference type
A type that refers to a specific memory location
get accessor
A type that refers to a specific memory location
constructor initializer
A type that refers to a specific memory location
default constructor
A type that refers to a specific memory location
set accessor
A type that refers to a specific memory location
default value
A type that refers to a specific memory location
contextual keywords
A type that refers to a specific memory location
class client
A type that refers to a specific memory location
class header
A program or class that instantiates objects of another prewritten class
reference type
A program or class that instantiates objects of another prewritten class
get accessor
A program or class that instantiates objects of another prewritten class
constructor initializer
A program or class that instantiates objects of another prewritten class
default constructor
A program or class that instantiates objects of another prewritten class
set accessor
A program or class that instantiates objects of another prewritten class
default value
A program or class that instantiates objects of another prewritten class
contextual keywords
A program or class that instantiates objects of another prewritten class
class client
A program or class that instantiates objects of another prewritten class
class header
An alternative to repeating code in the constructors
reference type
An alternative to repeating code in the constructors
get accessor
An alternative to repeating code in the constructors
constructor initializer
An alternative to repeating code in the constructors
default constructor
An alternative to repeating code in the constructors
set accessor
An alternative to repeating code in the constructors
default value
An alternative to repeating code in the constructors
contextual keywords
An alternative to repeating code in the constructors
class client
An alternative to repeating code in the constructors
class header
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
42
Explain what a destructor is and why it cannot be overloaded.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 42 flashcards in this deck.