Initialization of Java Review

Source: Internet
Author: User

Initialize block

Java uses constructors to complete state initialization, similar to constructors for initializing blocks

When you create a Java object, you always call the initialization block first, and if you have more than one block, it executes sequentially in order, and initialization is always performed implicitly when the Java object is created and
Constructor before executing

public class Person {{int a=6;if (a>4) {System.out.println ("initialization block for person: local variable greater than 4");//Note this is a local variable}}{ System.out.println ("The second initialization block of person");//Although it is possible to define two initialization blocks, there is no OVA with}public person () {System.out.println ("no argument constructor for person");} public static void Main (string[] args) {new person ();}} Initialization block for person: second initialization block with local variable greater than 4person no parameter constructor

  

Initialization of Java Review

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.