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

Examine the collapse of Han. What factors explain how this occurred? How influential in Han Dynasty on Chinese History?

Summarize effective communication strategies in organizational hierarchies, and review the role and relevance of the organizational grapevine

Examine the age-structure diagrams of Sweden and Kenya below, and answer the following questions. Compare and contrast the two age structure diagrams in terms of two population dynamics - birth rate and death rate.