Ch. 4 Flashcards
(20 cards)
The following code:
Account account1 = new Account(“Jane Green”);
passes the string argument “Jane Green” to the Account object’s Account method.
True.
False.
False
Which of the following properly declares an auto-implemented Name property of type string?
public string Name { get, set }
public string Name { get, set, }
public string Name { get; set; }
public string Name { get: set: }
public string Name { get; set; }
The code
myAccount.SetName(theName);
calls myAccounts’s SetName method, passing theName’s value as SetName’s argument.
True.
False.
True
The benefits of data integrity are automatic when instance variables are made private.
True.
False.
False
Which of the following statements is false?
Each object of a class shares one copy of the class’s instance variables.
Each class declaration is typically stored in a file having the same name as the class and ending with the .cs filename extension
Class, property and method names begin with an initial uppercase letter (i.e., Pascal case); variable names begin with an initial lowercase letter (i.e., camel case).
A class has attributes, implemented as instance variables. Objects of the class carry these instance variables with them throughout their lifetimes.
Each object of a class shares one copy of the class’s instance variables.
Which of the following statements about creating, compiling and running a Visual C# project with two classes is false?
The IDE automatically recognizes as the app’s entry point the class that contains Main.
When you select Build > Build Solution in Visual Studio, the IDE compiles all the files in the project to create the executable app.
If you do not build the app before running it, typing Ctrl + F5 will build the app first and run the app only if there are no compilation errors.
In a given project, declaring a Main method in more than exactly one class results in a runtime error.
In a given project, declaring a Main method in more than exactly one class results in a runtime error.
We could use a fully implemented Balance property to ensure that the set accessor’s argument is valid before assigning it to the balance instance variable.
True.
False.
True
Which of the following statements is false?
Each class you declare must provide a constructor with parameters that can be used to initialize an object when it’s created.
C# requires a constructor call for every object that’s created, so this is the ideal point to initialize an object’s instance variables.
A constructor’s identifier must be the class’s name.
When you declare a class, you can provide your own constructor to specify custom initialization for objects of your class.
Each class you declare must provide a constructor with parameters that can be used to initialize an object when it’s created.
An important difference between constructors and methods is that constructors must specify a return type of void.
True.
False.
False
Attempting to use an uninitialized local variable is a runtime error.
True.
False.
False
Type ________ is designed to precisely represent numbers with decimal points, especially monetary amounts.
digit
decimal
float
double
decimal
A method SetName might declare a parameter accountName to receive a new name to store in an Account object-a set accessor uses the implicitly declared keyword parameter for the same purpose.
True.
False.
False
Which of the following statements is false?
A decimal instance variable is initialized to zero by default.
By default, a property’s get and set accessors have the same access as the property.
A property’s get and set accessors must have the same access modifiers.
We can declare a Balance property’s set accessor private to indicate that it may be used only within its class, but not by the class’s clients.
A property’s get and set accessors must have the same access modifiers.
C# is case sensitive, so Name and name are distinct identifiers.
True.
False.
True
Which of the following statements is false?
Set and Get methods can validate attempts to modify private data and control how that data is presented to the caller, respectively.
If an instance variable were public, any client of the class could see the data and modify it, including setting it to an invalid value.
public data allows client-code programmers to write code that depends on the class’s data format. If the class’s owner changes that format, any client code dependent on it would “break” and would need to be adjusted to the new format, making it subject to break again.
None is false. All of the above are true.
None is false. All of the above are true.
Consider the code:
myAccount.Name = theName;
which assigns the string theName to myAccounts’s Name property. Which of the following is false regarding when property Name is invoked by the expression myAccount.Name on the left of an assignment?
The app transfers program execution to Name’s set accessor.
Property Name’s set accessor performs its task-that is, it stores in the myAccount object’s name instance variable the string value that was assigned to property Name.
When Name’s set accessor completes execution, program control returns to where the Name property was accessed, then execution continues at the next statement.
All of the above are true.
All of the above are true.
A method such as Main “drives” an object by calling its methods-without having to know how the class’s internal mechanisms work. In this sense, the class containing method Main is referred to as a driver class.
True.
False.
True
Making a class’s instance variables public and its methods private and accessing those instance variables only through the class’s methods and properties facilitates debugging, because problems with data manipulations are localized to the methods (and properties).
True.
False.
False
Consider the code:
myAccount.SetName(theName);
Which of the following statements is false?
When this method executes, the argument value in the call’s parentheses (i.e., the value stored in theName) is copied into the corresponding parameter in the method’s header.
Each parameter must specify a type followed by a parameter name. When there are multiple parameters, they are placed in a comma-separated list.
The number and order of arguments in a method call must match the number and order of parameters in the method declaration’s parameter list.
All of the above are true.
All of the above are true.
Normally, constructors are declared private.
True.
False.
False