3.10. Review notes

This section lists the main points covered in this chapter.

Scope of variables:

  • Variables can have multiple scopes: class, instance, local, and method parameters.
  • Local variables are defined within a method. Loop variables are local to the loop within which they’re defined.
  • The scope of local variables is less than the scope of a method if they’re declared in a sub-block (within braces, {}) in a method. This sub-block can be an if statement, a switch construct, a loop, or a try-catch block (discussed in chapter 7).
  • Local variables can’t be accessed outside the method in which they’re defined.
  • In a method, a local variable can’t be accessed before its declaration.
  • Instance variables are defined and accessible within an object. ...

Get OCA Java SE 8 Programmer I Certification Guide 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.