This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Class and instance variables are automatically given a starting value when the class is loaded or the instance is created. Variables declared inside a method are not. Think about what the += operator does - it takes the existing value in a variable and adds to it. Therefore the compiler watches out for the possibility that num2 does not have a starting value assigned. Automatically zeroing memory that a new object is going to occupy is part of the built-in security design of Java. In languages that don't do this, it is possible to grab a large hunk of memory that might have been used for data by a previous application and fish around in it for things like passwords. Bill