This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Well I'm back, lol. Thank you all for the great advise, has help alot.
Have all 3 programs written with only 2 Errors.
Can someone help explain the following to me? -Called Compiler C:\PROGRA~1\Java\JDK15~1.0_0\bin\javac.exe- -Target File: G:\NEW9~1\CheckingAccountsTest.java- G:\NEW9~1\CheckingAccountsTest.java:98: variable currentAcccount might not have been initialized sumOfBeginningBalances += currentAcccount.getBalance(); ^ G:\NEW9~1\CheckingAccountsTest.java:130: variable currentAcccount might not have been initialized sumOfBeginningBalances += currentAcccount.getBalance(); ^ 2 errors
I think that the problem is that the variable in question is a local variable and it is initialized inside of a conditional. I think that you need to initialize it in the main block of code for that method.
yes, local variables MUST be explicitly initialised before they're first read. If you initialise them in conditional statements structured in a way that the compiler cannot ascertain one will always be executed, it will generate that error. Either restructure your conditionals so the compiler can ascertain your local will always be initialised (if possible) or initialise it explicitly to something at declaration (most people use null for that).