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

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?