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

What is JAD and how are users involved? What are advantages and disadvantages of JAD?

Describe at least three of the general information skills essential for all business careers.

Why do firms need to invest in net working capital?