go to previous page   go to home page   go to next page highlighting

Answer:

The static method changes the class variable. The main method prints out the value currently in the variable, which is not what it started with.


Global Confusion

scope of N

You might say that the problem is obvious so there is no reason to avoid global variables. But this program has 10 lines of code. Try finding a problem like this in a program of 50,000 lines. Confusion reigns.

Toyota cars experienced unintended acceleration 2009 - 2011 resulting in several deaths. Part of the problem was the many global variables in the throttle control program. Toyota has (so far) paid $1.2 billion in damages.

Modularity is important.


QUESTION 14:

Can a static method call another static method?


go to previous page   go to home page   go to next page