L5 Practice Quiz: Ch 4 Creating Your Own Class
____ are special methods used to read the current state or value of an object member's data. Mutators Setters Constructors Accessors
Accessors
Which of the following is NOT one of the inherited member methods of the object class? Equals( ) GetType( ) ToString( ) Main( )
Main( )
After a project has been created and a new class added to your application, you can use the ____________ Window in Visual Studio to create a class diagram.
Solution Explorer
WriteLine("Value = {0:N0}", 12345.9032); What will be displayed from the above line?
Value = 12,346
The ToString( ) method is automatically invoked when an object reference is made in the ____. mutator method class constructor object class Write() method
Write() method
To design a class that is flexible and full-featured, ____. a) include multiple constructors. b) define at least three constructors. c) define a default constructor. d) define a constructor for every possible combination of data members.
a) include multiple constructors.
Constructors ____. do not have to be written. can be overloaded. all of the above. do not return a value.
all of the above
When you define the class, you describe its ____ in terms of data and its behaviors, or methods, in terms of what kinds of things it can do. characteristics attributes fields all of the above
all of the above
plush.PricePerSqYard = 40.99; If proper naming conventions were used in the above statement, which of the following statements is true? all of the above PricePerSqYard is a property plush is an object 40.99 is a numeric literal
all of the above
Local variables ____. must be defined as private are defined in classes are defined inside Main( ) and other methods determine the data characteristics for the class
are defined inside Main() and other methods
The body of the constructor methods consist primarily of ____________.
assignment statements
When you define the class, you describe its ____________, or characteristics or fields, in terms of data.
attributes
Which of the following is true regarding methods of a class? a) You must use the keyword static. b) They are called instance methods. c) No return type is used when you define a class method. d) To call methods of the class in the class, you must prefix the method name with the class name.
b) They are called instance methods.
To add full functionality to your classes, ____. a) write a default constructor b) omit writing a constructor so that the default one will be created for you c) write more than one constructor d) write at least five constructors for each class
c) write more than one constructor
By abstracting out the attributes (data) and the behaviors (processes on the data), you can create a(n) ____________ to serve as a template from which many objects of that type can be instantiated.
class
C# is an object-oriented language as such all the code that you write has to be placed in a(n) ____________.
class
C# is an object-oriented language. All the code for an application must be placed in a(n) ____. class file object method
class
After the class diagram is created, add the names of data members or fields and methods using the_________________ section.
class details
Which of the following is NOT a true statement relating to constructors? a) To add full functionality to your classes, write multiple constructors b) Constructors are used to provide values to the object's data members. c) If you write one constructor, you lose the default one that is created automatically. d) The default constructor must be the first one written for the class.
d) The default constructor must be the first one written for the class
In order to test a class, ____. a) use the properties to assign and retrieve values. b) a different class is needed. c) invoke instance methods using the objects you construct. d) all of the above.
d) all of the above.
A property resembles a(n) ____, but is more closely aligned to a(n) ____. method, data field data field, method mutator, accessor object, mutator
data field, method
Instance methods manipulate data by ____. sending visible data in the Main( ) method. using constructors and accessors. passing information as arguments through parameters. directly accessing private data members.
directly accessing private data members.
A class is normally associated with a(n) ____, which often describes a person, place, or thing and is normally a noun. entity method member data member behavior
entity
A constructor is used to instantiate a class from an object. true or false
false
A private access modifier is always associated with data members, methods, and constructors of a class. true or false
false
A property looks like a method because it directly represents a storage location. true or false
false
All data types are initialized to 0 when an object is constructed. true or false
false
If you overwrite the ToString( ) method, you should also override the other methods of the object class. true or false
false
Instance methods must have the static keyword in their heading. true or false
false
Mutators are special types of methods used to create objects. true or false
false
Use a type prefix, such as C for class name. For example, a student class should be named CStudent. true or false
false
When you define a class method, you define its characteristics or fields in terms of the data. true or false
false
Accessors are also referred to as ____. getters properties mutators classes
getters
Accessor and mutators are ____________ methods
instance
The static keyword must not be used with ____. class methods instance methods all of the above data members
instance methods
Fields or data members are also called ____________.
instance variables
Constructors are used to ____________ a class.
instantiate
When you define a class, you can use ____ to display all public members of the class (once an object is instantiated). class diagrams intellisense instance methods constructors
intellisense
Instance methods are ____. defined outside of the class. nonstatic methods. also called class methods. defined in the Main( ) method.
nonstatic methods
To program an object-oriented solution begin by determining what ____ are needed in the solution. processes objects methods data
objects
Variables declared in the Main( ) method are ____. visible inside any method in the class. only visible inside Main( ). are automatically initialized to zero. must be defined as private data members.
only visible inside Main()
Class methods manipulate data by ____. passing information as arguments through parameters. sending visible data in the Main( ) method. directly accessing private data members. using constructors and accessors.
passing information as arguments through parameters.
Data members should be defined with an access mode of ____________.
private
Normally data members are defined to have ____ access. protected private internal public
private
Accessors, mutators, and other instance methods are normally defined with what type of access modifier? initial private public protected
public
Constructors should be defined with a ____ access modifier. static private protected public
public
____________ access modifier is always associated with constructors.
public
To define a property to change a data member of a class include a ____ clause. value set mutator get
set
As with overloaded methods, ____________ must differ for constructors.
signatures
A class named River will have a constructor named River. true or false
true
Constructors are methods. true or false
true
Since the data members of the class are defined as private, their public property counterpart must be used to assign new values to the data members. true or false
true
The ToString( ) method is automatically invoked when the Write( ) or WriteLine( ) methods are called. true or false
true
Three of the contextual keywords associated with properties are get, set, and value. true or false
true
In order to provide a new definition for the ToString( ) method, ____. use the keyword override in the heading it must be defined using the new operator. there must be at least one constructor defined. both mutators and accessors must have been defined.
use the keyword override in the heading
Constructors differ from other methods in that constructors ____. are defined outside of the class always return a value are not defined by the programmer use the same identifier as the class
use the same identifier as the class