Static variables can't be local why ??

Because  In C and C++, you can have local static variables. The scope of such variables is the method they are defined in, but they continue to exist when the method ends. Next time the same method is called, such a variable will still have the value it had when the method was called the previous time. 
 Although Java took a number of features from C++, it isn't the same as C++, and this feature was left out. Probably the designers of the Java language didn't think this was a very useful feature to borrow from C++. So, This is not a feature that you really need, and it can be hard to understand. 


No comments:

Post a Comment