Provide a reason why an instance data would be declared static.

Provide a reason why an instance data would be declared static. 

Answer:  If an instance data is to be shared among all objects of the class, the instance data would be static.  As an example, an instance data that counts the number of times something has happened across all objects of the class would be made static.  If we are writing a chess game and have a ChessPiece class that includes a method called movePiece, we would want to know how many moves a player has made, but not necessarily how many times a single piece has been moved.  So, all of the ChessPieces share a numberOfTimesMoved instance data that is incremented by any ChessPiece whenever it is moved.

Comments

Popular posts from this blog

Discuss the seven characteristics of useful information.

Why have accounting software packages been designed with separate transaction modules?

A laboratory assistant prepared solution of 0.8 M, 0.6 M, 0.4 M, and 0.2 M sucrose, but forgot to label them. After realizing the error, the assistant randomly labeled the flasks containing these four unknown solutions as flask A, flask B, flask C, and flask D.