Deck 9: Using Classes and Objects
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Match between columns
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/42
Play
Full screen (f)
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) 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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()
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;
}
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
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
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?
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
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;}
}
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
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