Default (default) value for Java variables-only the instance and static variables of the class are

Source: Internet
Author: User
Tags count variables reference variable
Variable

The JVM assigns the default value (the default) to the class's instance and static variables, including every element in the array arrays-without having to write the initialization assignment statement again.

Remember: Local variables have no default values and must be initialized manually!

This default assignment process is done before the object's constructor call, and if the program writes an initial value statement for the instance and static variables, and the values given are the JVM default values, then it is definitely the superfluous and repetitive work.

As the following code illustrates how to gild the lily:

Situation One:

public class Foo {
private int count=0; Extra
private static Boolean dd=false; Extra
Public Foo ()
{
Super ();
}
}

Situation Two:

public class Foo {
private int count;
private static Boolean DD;
Public Foo ()
{
Super ();
count=0; Extra
Dd=false; Extra

}
}

The default values for a variable or object reference are as follows:

int:0
byte:0
long:0
shor:0
float:0.0
double:0.0
Boolean:false
Char: ' \u0000 '
Object Reference:null



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.