Web server - 440 Object-Based Programming Chapter 8 object-based programming (OBP)

440 Object-Based Programming Chapter 8 object-based programming (OBP) rapid applications development (RAD) object-oriented programming (OOP) reusable code package access services of a class package statement set method predicate method software reusability principle of least privilege static class variable private static method programmer-defined type this reference public user-defined type public interface of a class utility method query method SELF-REVIEW EXERCISES 8.1 Fill in the blanks in each of the following statements: a) Class members are accessed via the operator in conjunction with a reference to an object of the class. b) Members of a class specified as are accessible only to methods of the class. c) A is a special method used to initialize the instance variables of a class. d) A method is used to assign values to private instance variables of a class. e) Methods of a class are normally made and instance variables of a class are normally made . f) A method is used to retrieve values of privatedata of a class. g) The keyword introduces a class definition. h) Members of a class specified as are accessible anywhere an object of the class is in scope. i) The operator dynamically allocates memory for an object of a specified type and returns a to that type. j) A instance variable represents class-wide information. k) The keyword specifies that an object or variable is not modifiable after it is initialized. l) A method declared static cannot access class members. 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) final. l) nonstatic. EXERCISES 8.2 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 method that enables an object of this class to be initialized when it is declared. Provide a no-argu Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01

Leave a Reply