Provide a reason why a method would be declared static.

Provide a reason why a method would be declared static.

Answer:  A method is declared static if it might be used, not by the current object, but by any objects of the class.  That is, the method does not require access to any single object’s instance data.  Consider a class called Point that consists of an x and y coordinate.  To determine the distance between two Points, we could make a static computeDistance method.  It is passed two Points as parameters and computes the distance.  Another example is the Keyboard class from the textbook, which does not itself have any instance data.

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?