Code block: Code enclosed in Java with {}

Source: Internet
Author: User

Code block: Code enclosed in Java with {} 

 (1) Code enclosed in {} in Java.
  (2) Code block classification: (depending on its location and declaration)
    A: Local code block
In the method definition, it is used to qualify the life cycle of a variable, release it early, and improve memory utilization.
    B: Building Blocks of code
Appearing outside of a method in a class (that is, in a member position in a class), you can put together the same code in multiple construction method methods to initialize the object, execute each call to the construction method, and execute before the method is constructed.
    C: Static code block
Occurs outside of a method in a class (that is, a member position in a class), with the static modifier used to initialize the class, which executes at the time the class is loaded and executes only once.
    D: Synchronizing code blocks
Multi-threaded section explained.
  (3) Interview questions:
Static block of code, Construction code block, the execution order of the construction method problem?

Static code blocks > Constructing code blocks > Construction Methods

Executes only once per call construction method

As shown in the following:

Code block: Code enclosed in Java with {}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.