简体   繁体   中英

Java doc for Scope of variables

Can anyone guide me to the java documentation for the scope of the variables . I would like to have a look at the java documentation for the class variables and member variables in java 8 but can't find it . Please guide me through it . Thanks in advance.

You need Java Language Specification not Java docs.
Here's the link for it https://docs.oracle.com/javase/specs/jls/se8/html/index.html

You might be able to find a tutorial with a more user-friendly description, but the canonical documentation of identifier scope can be found in the Java Language Specification, specifically in Section 6.3 , "Scope of a Declaration".

The relevant statements concerning variables are:

  • The scope of a declaration of a member m declared in or inherited by a class type C (§8.1.6) is the entire body of C, including any nested type declarations.
  • The scope of a declaration of a member m declared in or inherited by an interface type I (§9.1.4) is the entire body of I, including any nested type declarations.
  • The scope of a local variable declaration in a block (§14.4) is the rest of the block in which the declaration appears, starting with its own initializer and including any further declarators to the right in the local variable declaration statement.
  • The scope of a local variable declared in the ForInit part of a basic for statement (§14.14.1) includes all of the following:

    • Its own initializer

    • Any further declarators to the right in the ForInit part of the for statement

    • The Expression and ForUpdate parts of the for statement

    • The contained Statement

  • The scope of a local variable declared in the FormalParameter part of an enhanced for statement (§14.14.2) is the contained Statement.

  • The scope of a parameter of an exception handler that is declared in a catch clause of a try statement (§14.20) is the entire block associated with the catch.

  • The scope of a variable declared in the ResourceSpecification of a try-with-resources statement (§14.20.3) is from the declaration rightward over the remainder of the ResourceSpecification and the entire try block associated with the try-with-resources statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM