Initialization Phase: Initializing Variables total and gradeCounter
The assignments (in lines 13–14) initialize total
to 0
and gradeCounter
to 1
. These initializations occur before the variables are used in calculations.
Common Programming Error 4.3
Using the value of a local variable before it’s initialized results in a compilation error. All local variables must be initialized before their values are used in expressions.
Error-Prevention Tip 4.3
Initialize each total and counter, either in its declaration or in an assignment statement. ...
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.