340 Object-Based Programming (Anonymous web server) Chapter 8 8.2 State whether

340 Object-Based Programming Chapter 8 8.2 State whether each of the following is true of false. If false explain why. a) All objects are passed by reference. b) Constructors can have return values. c) Properties must define get and set accessors. d) The this reference of an object is a reference to that object itself. e) A static member can be referenced when no object of that type exists. f) A static member of a class can be referenced through an instance of the class. g) Variables declared constmust be initialized either in a declaration or in the class constructor. h) Different namespaces cannot have classes/methods with the same names. i) Assembly files are not required to define an entry point (Main method). j) Indexers can return any type in C#. ANSWERS TO SELF-REVIEW EXERCISES 8.1 a) dot (.). b) private. c) constructor. d) set. e) public, private. f) get. g) class. h) public. i) new, reference. j) static. k) readonly. l) non-static. 8.2 a) True. b) False. Constructors are not permitted to return values. c) False. A property definition can specify a set accessor, a get accessor or both. d) True. e) True. f) False. A static member of a class can only be referenced through the class name. g) False. Variables declared const must be initialized when they are declared. h) False. Different namespaces can have classes/methods with the same names. i) True. j) True. EXERCISES 8.3 Create a class called Complex for performing arithmetic with complex numbers. Write a driver program to test your class. Complex numbers have the form realPart + imaginaryPart * i where i is -1 Use floating-point variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared. Provide a no-argument constructor with default values in case no initializers are provided. Provide public methods for each of the following: a) Addition of two Complex numbers. The real parts are added together and the imaginary parts are added together. b) Subtraction of two Complex numbers. The real part of the right operand is subtracted from the real part of the left operand and the imaginary part of the right operand is subtracted from the imaginary part of the left operand. c) Printing of Complex numbers in the form (a, b), where a is the real part and b is the imaginary part. 8.4 Modify the Date class of Fig. 8.8 to perform error checking on the initializer values for instance variables month, day and year. Also, provide a method NextDayto increment the day by one. The Date object should always remain in a consistent state. Write a program that tests the NextDay method in a loop that prints the date during each iteration of the loop to illustrate that the NextDay method works correctly. Be sure to test the following cases:
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Leave a Reply