Deck 9: Using Classes and Objects

Full screen (f)
exit full mode
Question
What do accessors do within the C# language?

A) They define how an instantiation of a class behaves.
B) They control access to the various properties of a class.
C) They provide access to a field of a class.
D) They specify the statements that execute when a class's fields are accessed.
Use Space or
up arrow
down arrow
to flip the card.
Question
Predefined types such as int, double, and char are all examples of what component of the C# language?

A) reference types
B) value types
C) output types
D) pointer types
Question
You can overload an operator for a built-in data type.For example, you can change the meaning of + between two ints.
Question
Where are the data components of a class that differ for each object stored?

A) Inside of instance variables.
B) In variable unit states.
C) Inside constants
D) Inside parent object relationships.
Question
Only nonstatic methods receive a this reference.
Question
What reference is passed implicitly and invisibly to every instance method and property accessor?

A) static
B) object
C) use
D) this
Question
Besides being known as a class client, what is a class that instantiates objects of another prewritten class known as?

A) a class state
B) a class instantiation
C) a class user
D) a server class
Question
What is another name used for instance variables in order to help distinguish them from other variables you might use?

A) states
B) relationships
C) instantiations
D) fields
Question
What class access modifier should you utilize to limit access to the assembly (a group of code modules compiled together) to which the class belongs?

A) private
B) internal
C) protected
D) public
Question
What class access modifier means that access to the class is not limited?

A) protected
B) private
C) internal
D) public
Question
What happens if you do not explicitly include an access specifier?

A) Its access modifier will be public by default.
B) It will be assumed as an internal field.
C) Its access modifier will be private by default.
D) It will be set to protected.
Question
If you don't write a constructor for a class object, C# writes one for you.
Question
A GUI object, such as a Button, is represented as an object that cannot encapsulate any methods.
Question
What class access modifier is used to indicate that access is limited to another class to which the class belongs?

A) private
B) internal
C) protected
D) public
Question
A parameter that is undeclared and that gets its value automatically is considered to be what type of parameter?

A) implicit
B) explicit
C) instance
D) property
Question
What class access modifier can be used to indicate 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
Using private fields within classes is an example of what feature found in all object-oriented languages?

A) information hiding
B) polymorphism
C) inheritance
D) overloading
Question
When you create an array of objects, the array holds the actual value of each of the objects.
Question
What kind of constructor takes no arguments whatsoever?

A) object constructor
B) default constructor
C) construct initializer
D) construct array
Question
What are the set of attributes of an object's instance variable known as?

A) The object's relationship.
B) The object's state.
C) The object's class instantiation.
D) The object's fields.
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 statement regarding the use of destructors is accurate?

A) A destructor performs actions when a class is instantiated.
B) A destructor must be explicitly created.
C) To declare a destructor, you must use a dash - followed by the class name.
D) You cannot provide any arguments to a destructor.
Question
Classes that support simple data items each contain a method that provides the details of how items in the class compare to each other.What is the name of this method?

A) Equals()
B) Less()
C) IndexOf()
D) CompareTo()
Question
A member of a class that provides access to a field of a class is referred to as what?

A) implicit parameter
B) property
C) explicit parameter
D) reference type
Question
What consists 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) A C# multifile assembly.
B) A defined framework.
C) A properly implemented interface.
D) A class destructor.
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
What contains the actions you require when an instance of a class is destroyed, such as when the instance goes out of scope?

A) class constructor
B) constructor initializer
C) destructor
D) parameterless constructor
Question
What interface in C# 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
What kind of property is one in which the code within the accessors is created automatically?

A) auto-implemented property
B) polymorphic property
C) dynamic property
D) abstract property
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
Even though you can't specify this modifier for a named constant within a class, what is the effective access modifier for the constant?

A) public
B) private
C) static
D) internal
Question
What happens when a method overrides another method?

A) It instantiates that method and takes over its properties.
B) It takes precedence over the original method, hiding it.
C) It overloads the original method, allowing for varying parameters.
D) It extends the original method, adding additional functionality.
Question
Explain what a destructor is and why it cannot be overloaded.
Question
As an alternative to repeating code in multiple constructors, what can be used to indicate 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
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
What are the class access modifiers in C#?
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
Briefly describe what an object initializer does and give a specific example.When is the object initializer assignment made?
Question
What is the difference between overriding a method and overloading a method with respect to method signatures?
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/39
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 9: Using Classes and Objects
1
What do accessors do within the C# language?

A) They define how an instantiation of a class behaves.
B) They control access to the various properties of a class.
C) They provide access to a field of a class.
D) They specify the statements that execute when a class's fields are accessed.
D
2
Predefined types such as int, double, and char are all examples of what component of the C# language?

A) reference types
B) value types
C) output types
D) pointer types
B
3
You can overload an operator for a built-in data type.For example, you can change the meaning of + between two ints.
False
4
Where are the data components of a class that differ for each object stored?

A) Inside of instance variables.
B) In variable unit states.
C) Inside constants
D) Inside parent object relationships.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
5
Only nonstatic methods receive a this reference.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
6
What reference is passed implicitly and invisibly to every instance method and property accessor?

A) static
B) object
C) use
D) this
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
7
Besides being known as a class client, what is a class that instantiates objects of another prewritten class known as?

A) a class state
B) a class instantiation
C) a class user
D) a server class
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
8
What is another name used for instance variables in order to help distinguish them from other variables you might use?

A) states
B) relationships
C) instantiations
D) fields
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
9
What class access modifier should you utilize to limit access to the assembly (a group of code modules compiled together) to which the class belongs?

A) private
B) internal
C) protected
D) public
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
10
What 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 39 flashcards in this deck.
Unlock Deck
k this deck
11
What happens if you do not explicitly include an access specifier?

A) Its access modifier will be public by default.
B) It will be assumed as an internal field.
C) Its access modifier will be private by default.
D) It will be set to protected.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
12
If you don't write a constructor for a class object, C# writes one for you.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
13
A GUI object, such as a Button, is represented as an object that cannot encapsulate any methods.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
14
What class access modifier is used to indicate that access is limited to another class to which the class belongs?

A) private
B) internal
C) protected
D) public
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
15
A parameter that is undeclared and that gets its value automatically is considered to be what type of parameter?

A) implicit
B) explicit
C) instance
D) property
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
16
What class access modifier can be used to indicate 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 39 flashcards in this deck.
Unlock Deck
k this deck
17
Using private fields within classes is an example of what feature found in all object-oriented languages?

A) information hiding
B) polymorphism
C) inheritance
D) overloading
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
18
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 39 flashcards in this deck.
Unlock Deck
k this deck
19
What kind of constructor takes no arguments whatsoever?

A) object constructor
B) default constructor
C) construct initializer
D) construct array
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
20
What are the set of attributes of an object's instance variable known as?

A) The object's relationship.
B) The object's state.
C) The object's class instantiation.
D) The object's fields.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
21
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 39 flashcards in this deck.
Unlock Deck
k this deck
22
What statement regarding the use of destructors is accurate?

A) A destructor performs actions when a class is instantiated.
B) A destructor must be explicitly created.
C) To declare a destructor, you must use a dash - followed by the class name.
D) You cannot provide any arguments to a destructor.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
23
Classes that support simple data items each contain a method that provides the details of how items in the class compare to each other.What is the name of this method?

A) Equals()
B) Less()
C) IndexOf()
D) CompareTo()
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
24
A member of a class that provides access to a field of a class is referred to as what?

A) implicit parameter
B) property
C) explicit parameter
D) reference type
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
25
What consists 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) A C# multifile assembly.
B) A defined framework.
C) A properly implemented interface.
D) A class destructor.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
26
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 39 flashcards in this deck.
Unlock Deck
k this deck
27
What contains the actions you require when an instance of a class is destroyed, such as when the instance goes out of scope?

A) class constructor
B) constructor initializer
C) destructor
D) parameterless constructor
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
28
What interface in C# 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 39 flashcards in this deck.
Unlock Deck
k this deck
29
What kind of property is one in which the code within the accessors is created automatically?

A) auto-implemented property
B) polymorphic property
C) dynamic property
D) abstract property
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
30
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 39 flashcards in this deck.
Unlock Deck
k this deck
31
Even though you can't specify this modifier for a named constant within a class, what is the effective access modifier for the constant?

A) public
B) private
C) static
D) internal
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
32
What happens when a method overrides another method?

A) It instantiates that method and takes over its properties.
B) It takes precedence over the original method, hiding it.
C) It overloads the original method, allowing for varying parameters.
D) It extends the original method, adding additional functionality.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
33
Explain what a destructor is and why it cannot be overloaded.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
34
As an alternative to repeating code in multiple constructors, what can be used to indicate 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 39 flashcards in this deck.
Unlock Deck
k this deck
35
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 39 flashcards in this deck.
Unlock Deck
k this deck
36
What are the class access modifiers in C#?
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
37
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 39 flashcards in this deck.
Unlock Deck
k this deck
38
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 39 flashcards in this deck.
Unlock Deck
k this deck
39
What is the difference between overriding a method and overloading a method with respect to method signatures?
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 39 flashcards in this deck.