throbber
Z O F
`
`- O L
`
`nJ
`
`MI CROGRAFX—2 04 9
`
`II
`
`- Q 3 O1
`
`;
`
`

`
`; 5 COURSE TECHNOLOGY
`In CENGAGE Learning‘
`
`Object-Oriented Programming
`Using CH. Fourth Edition
`Joyce Farrell
`
`Executive Editor: Marie Lee
`
`Acquisitions Editor: Amy Joltymore
`
`Managing Edhoc Tricia Cole
`
`Developmental Edhoc Lise Rutfolo
`Editorial Assistant: Patrick Frank
`
`Marketing Manager: Bryant chrzan
`
`Content Protect Manager: Erin Dowler
`Art Director: Bruce Bond
`
`Manufeaurtng Coorditator:
`Jullo Esperas
`
`Prootreader: Wendy Benedetto
`
`Cover Designer: Bruce Bond
`
`Cover Photo: 0 iStocirphoto.ooml
`Storman
`
`Compoeion International Typesetting
`and Composition
`
`0 2009 Course Technology. Cengage Leeming
`
`ALL RIGHTS RESERVED. No part ol this work covered by the copyright
`herein may be reproduced. transmitted. stored or used In any form or by
`any means—graphic. electronic. or mechanical. including but not limited
`to photocopying, recording. scanning. digitizing. taping. Web dtsirbutlon.
`lnlormation networks. or inlormatiori storage and retrieval systems. except
`as pennited under Section 107 or 103 of the 1976 United States
`Copyright Act—wlthout the prior written permission of the ptblisher.
`
`For product lntormatlon and technology assistance. contact us at
`Cengege Learning Customer & Sales Support, 1-800-354-9106
`
`Forpermission louse materieltromthtsteudorproduct.
`submit all requests onllne at cengage.cornl‘permlasions
`Further permissions questions can be e-mailed to
`pennlsalonrequestflcengagmcom
`
`ISBN-13: 978-1-4239-0257-7
`
`ISBN-10: 1-4239-0257-2
`
`course Technology
`25 Thomson Place
`
`Boston. MA 02210
`USA
`
`Cengage Learning is a leading provider ol customised learning solutions with
`otfioe locations around the globe. Including Shgapore. the Unled Kingdom.
`Australia. Mexico. Brazl. and Japan. Locate your local otfioe at
`tnternationaI.cengage.comIregion
`
`Cengage Leamlng products are represented in Canada by Nelson
`Education. Ltd.
`
`For your ifelong teeming solutions. visit course.cengage.com
`
`Purchase any oi our products at your local college store or at our
`preterred onite store \vvrur.lcltaptere.com
`
`Some of the product names and company names used it this book have
`been used tor tdentltlcatlon purposes only and may be trademarks or
`registered trademarks of their respective manufacturers and sellers.
`
`Course Technology, a part of Cengage Leeming. reserves the right to
`revise this publication and metro changes irom time to time In its content
`without notice.
`
`Printed in the United States of America
`
`12345671211 100908
`
`Copyright 2009 Cengage Learning. Inc. All Rights Reserved. May not be copied. scanned. or duplicated. in whole or in part.
`
`

`
`CHAPTERSEVEN
`
`USING STATIC CLASS MEMBERS
`
`A CH object is an instantiation of a class that can contain both data members and methods.
`When you create an object. a block of memory is set aside for the data members. Just as the
`declaration int :4; reserves enough space in your system to hold an integer. the declaration
`student onestudent; reserves enough storage in your system to hold a student object. For
`example. if a Student is defined to contain an integer ID number and a double grade point
`average. then each time a student object is declared. enough memory for both the integer and
`the double is reserved. This makes sense. because every student object requires its own ID
`and grade point . verage. Fields such as idnumbez and gradePoint.Average are instance
`fieltb or imtance variables because you store a separate copy of each instance of the class.
`
`When objects are instantiated, each one gets its own block of memory for its data members.
`If you create two students, you reserve two blocks of memory; if you create an array of 100
`objects. 100 blocks of memory are set aside.
`
`Sometimes every instantiation of a class requires the same value. For example, you might
`want every Student object to contain a data member that holds the student athletic lee—a
`value that is the same for all Students. lfyou declare 100 Student objects, all students
`need their own ID and grade point average, but not all students need their own copy of
`the athletic fee figure. If each student: object contains a copy of the athletic fee. you repeat
`the same infonnation l()() times, wasting memory. To avoid this, you can declare the ath-
`letic fee variable as static, meaning that only one memory location is allocated. no matter
`how many objects of the class you instantiate. In other words, all members of the class
`share a single storage location for a static data member of that same class. A class vari-
`able that you declare to be static is the same for all objects that are instantiations of the
`class. Each instantiation of the class appears to be storing its own copy of the same value,
`but each actually just has access to the same memory location. The fields, such as the ID
`number, that are separate memory locations for each instance are non-static.
`
`edtlfl
`otuwvllilahilcremdcvetytiln
`D
`Wlulywenoleonui-Ifllcvlihlowilila
`tholtmion.
`lvclnlraIItltoproIlot.utlno‘nuca
`lIlIcIotI.1lIIvcrldihnlflIhavudlIuouadtI'uaIIltIlluutn
`Wliutwuuuuaunicvlhblmthovuibhtuimiuhsmuiuyuddrusamuulunvinhr
`iuttluptnomn.
`
`‘
`
`DEFINING STATIC DATA MEMBERS
`
`Because it uses only one memory location, a static data member is defined (given a value)
`in a single statement outside the class definition. Most often this statement appears just
`before the class implementation section. Consider the class and program in Figure 7-15. Note
`that in this example, the small student class contains just two fields. In this program. every
`object of the class that you ever instantiate receives its own copy of the non-static idNum
`field, but the same static ath1et:icE‘ee value applies to every class member that is ever
`instantiated. (The first shaded statement in Figure 7-15 shows the declaration of the field.)
`When the ma in (1 function declares two Student objects. at-‘reshman and asophomo re,
`they each possess their own idtlum value. but they share the athletic!-‘ee value. In the
`output shown in Figure 7-16. each object displays the same athletic fee.
`
`301
`
`Copyright 2009 Cengage Learning. Inc. All Rights Reserved. May not be copied. scanned. or duplicated. in whole or in pan.

This document is available on Docket Alarm but you must sign up to view it.


Or .

Accessing this document will incur an additional charge of $.

After purchase, you can access this document again without charge.

Accept $ Charge
throbber

Still Working On It

This document is taking longer than usual to download. This can happen if we need to contact the court directly to obtain the document and their servers are running slowly.

Give it another minute or two to complete, and then try the refresh button.

throbber

A few More Minutes ... Still Working

It can take up to 5 minutes for us to download a document if the court servers are running slowly.

Thank you for your continued patience.

This document could not be displayed.

We could not find this document within its docket. Please go back to the docket page and check the link. If that does not work, go back to the docket and refresh it to pull the newest information.

Your account does not support viewing this document.

You need a Paid Account to view this document. Click here to change your account type.

Your account does not support viewing this document.

Set your membership status to view this document.

With a Docket Alarm membership, you'll get a whole lot more, including:

  • Up-to-date information for this case.
  • Email alerts whenever there is an update.
  • Full text search for other cases.
  • Get email alerts whenever a new case matches your search.

Become a Member

One Moment Please

The filing “” is large (MB) and is being downloaded.

Please refresh this page in a few minutes to see if the filing has been downloaded. The filing will also be emailed to you when the download completes.

Your document is on its way!

If you do not receive the document in five minutes, contact support at support@docketalarm.com.

Sealed Document

We are unable to display this document, it may be under a court ordered seal.

If you have proper credentials to access the file, you may proceed directly to the court's system using your government issued username and password.


Access Government Site

We are redirecting you
to a mobile optimized page.





Document Unreadable or Corrupt

Refresh this Document
Go to the Docket

We are unable to display this document.

Refresh this Document
Go to the Docket