0% found this document useful (0 votes)
48 views

Static Variables

A class is created with a data member to hold a serial number for each object. Another data member counts the total number of objects created, which is used by the constructor to assign each new object its unique serial number. A member function allows each object to report its own serial number. A main() program then creates three objects and queries their serial numbers to test the class.

Uploaded by

MAHESH V
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Static Variables

A class is created with a data member to hold a serial number for each object. Another data member counts the total number of objects created, which is used by the constructor to assign each new object its unique serial number. A member function allows each object to report its own serial number. A main() program then creates three objects and queries their serial numbers to test the class.

Uploaded by

MAHESH V
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

1) Create a class that includes a data member that holds a "serial number" for each

object created from the class. That is , the first object created will be
numbered 1, the second 2 and so on,
To do this, you''' need another datamenber that records a count of how many objects
have been created so far.(This member should apply to the class as a whole; not to
the individual objects. What keyword
specifies this?) Then, as each object is created, its constructor can examine this
count memeber variable to determine the appropriate serial number for each object.
Add a member function that permits an object to report its own serial number. Then
write a main() program that creates three objects and quireies each one about its
serial number.
They should respond "I am object number 2 and so on".

You might also like