Class variables and local variables

Source: Internet
Author: User

There are two initial processes for the VM type variables. The first step is in the preparation phase, assign the system initial values (for example, the int type value 0 ), the second step is to assign the initial value defined by the programmer in the initialization phase. Therefore, the program will give the default value even if the class variable is not given the initial value. The Code is as follows: [java] public class MTest {int B; public void test () {System. out. println (B) ;}} [java] [java] But for local variables, local variables do not exist in the preparation stage of class variables. Therefore, if you do not assign values to local variables, a compilation error is reported. The code is as follows: [java] <pre name = "code" class = "java"> public class MucheTest {int B; public void test () {int; system. out. println (a) ;}}</pre> <br> the statement printed as a is incorrect, variable has no initial value <pre> </pre> <p> </p> <pre> </pre> <br> <p> </p>

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.