Java Interview Knowledge points

Source: Internet
Author: User

1. Publicstatic void Main () method, static and public can be swapped position, can be final decorated, can also be synchronize decorated.

2. A static block of code in a class executes before the main method, regardless of whether the static code block precedes or follows main. Precisely, this is because a static block of code executes when the class is loaded and executes only once. The main method is the class-loaded portal, which loads the class (new) when it encounters main, and then loads the static code block (either before or after main) before executing the contents of the main method. A non-static block of code is executed every time the new object. The static code block is loaded only once , and if main is already executed, then new is no longer executed.

3. Initialization order: The parent class takes precedence over the subclass, initializes the parent class and initializes the subclass, but note that the static code block is special, because the static code block is in the class load phase and takes precedence over other parts, so the parent class and subclass static code blocks are loaded, and the other parts of the parent class and subclass are loaded first.      

(1) Parent class static code blocks (including static initialization blocks, static properties, but not static methods)

(2) subclass static code blocks (including static initialization blocks, static properties, but not static methods)

(3)parent class non-static blocks of code (including non-static initialization blocks, non-static properties)

(4) Parent class constructor

(5) Subclass non-static block of code (including non-static initialization blocks, non-static properties)

(6) Sub-class constructors

4. Scope

5.

Java Interview Knowledge points

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.