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

JAD Advantages and Disadvantages

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

According to Hero (1992), how are the three major theories of government compared in their ability to help explain the relative position of racial and ethnic groups in US politics? Do you agree that the theory of two-tiered pluralism is better than the other two in explaining the Latino (and other nonwhite) position in the post-1965 era?