Chapter 4
C# Programming: From Problem Analysis to Program Design · 21 exercises
Problem 1
Objects are instances of _____ a. data members b. parameters c. properties d. methods e. classes
3 step solution
Problem 2
Properties are defined with access mode. a. public b. static c. private d. void e. protected
3 step solution
Problem 3
Which of the following modifiers is the most restrictive? a. private b. static c. public d. internal e. protected
2 step solution
Problem 4
Which of the following identifiers follows the standard naming convention for naming a class? a. \(\quad\) Calculate Final Grade b. MilesPerGallon c. Students d. Reports e. Employee
7 step solution
Problem 6
Which of the following is one of the user-defined methods inherited from the object class? a. ToString ( ) b. Main?? c. calculateAvg ( ) d. EqualsHashcode ( ) e. TypeHashcode( )
3 step solution
Problem 7
Properties are associated with the \(\quad\) of the class while methods are affiliated with the \(\quad\) of the class. a. activity, fields b. accessors, mutators c. objects, instances d. data, behavior e. behavior, data
4 step solution
Problem 8
Which of the following is a valid overloaded method for calculateAvg( )? int CalculateAvg (int val1, int val2) a. void CalculateAvg (int vall, int val2) b. int CalculateAvg (int vall, int val2) c. int CalculateAvg (double val1, double val2) d. double CalculateAvg (int vall, int val2) e. int CalculateAverage (int val2, int vall)
8 step solution
Problem 9
What operator is used to instantiate the class a. method b. plus symbol c. ToString ( ) d. new e. equal symbol
3 step solution
Problem 10
Instance variables are the same as: a. private member data b. local variables c. properties d. arguments e. parameters
7 step solution
Problem 11
Given the Employee class shown below, which of the following would be the most appropriate heading for its default constructor? public class Employee { a. public void Employee ( ) b. public Employee ( ) c. public static Employee ( ) d. private void Employee ( ) e. private Employee ( )
4 step solution
Problem 12
The following is probably an example of a(n) ____ public double GetYards ( ) a. constructor b. mutator c. \(\quad\) property d. accessor e. class definition
4 step solution
Problem 13
naming conventions, the property name for the following instance variable would be: private string name; a. propertyName b. nameProperty … # If you follow the standard C# naming conventions, the property name for the following instance variable would be: private string name; a. propertyName b. nameProperty c. getName d. name e. Name
4 step solution
Problem 14
Which of the following would be a valid call to the default constructor for the following class? public class Employee { a. Employee employee1 = new Employee ( ) ; b. Employee employeel = new undergrad () c. Employee employee1 d. Employee employeel = new Employee (default) e. Not enough information is given to be able to answer.
3 step solution
Problem 15
Given the following class definition, what would be a valid heading for a mutator? public class student public class Student private string name; private double gpa; a. public double SetGpa (double gpavalue) b. public void SetGpa (double gpavalue) c. public double SetGpa ( ) d. public void GetGpa (double gpavalue) e. public double setGpa ( )
4 step solution
Problem 17
is used with constructors? a. const b. private c. public d. static e. protected # Which of the following modifiers in C# is used with constructors? a. const b. private c. public d. static e. protected
5 step solution
Problem 18
Normally, member data uses a ______ access modifier, and methods use a ______ access modifier for object-oriented solutions. a. protected, public b. private, protected c. public, protected d. public, private e. private, public
4 step solution
Problem 19
For a class called Account that has data members of accountNumber, balance, and transactionAmount, which would be the most appropriate instance method heading for a method that reduces the transaction amount from the current balance? a. static double ReduceAccount (double accountBalance, double transactionAmount) b. double ReduceAccount (double accountBalance, double transactionAmount) c. static ReduceAccount ( ) d. void ReduceAccount ( ) e. static void ReduceAccount ( )
4 step solution
Problem 20
In order to provide a new definition for the ToString ( ) method, what keyword is added to the method heading? a. static b. override c. new d. overload e. public
4 step solution
Problem 22
Explain how instance methods differ from class methods. What differs when you want to invoke each different type? Which one requires an object in order for it to be called?
5 step solution
Problem 23
What does it mean to override a method? Why should the ToString ( ) method be overridden for user-defined classes?
4 step solution
Problem 24
Explain the role of the constructor. What is the default constructor? When do you automatically get a default constructor?
3 step solution