The Java "Tij" validates the default initialization results of Java for members of the base data type of a class __java

Source: Internet
Author: User

When we define a class that has members of the base data type in the class, but does not initialize them,

This time, if we use this variable, Java will initialize them by default.

Note: Java only initializes the base type members in the class, and if the basic data type is not initialized in the method,

Compile at this time will be an error. (c, the report will be reported to the police in C + +).

To avoid unnecessary problems, it is advisable to manually initialize all data types and objects at design time.

The following table shows the default values for the base type.


Java default initialization of the base data type
Basic type Default value
Boolean False
Char ' \u0000 ' (space)
Byte (byte) 0
Short (short) 0
Int 0
Long 0L
Float 0.0f
Double 0.0d


Here is a simple validation Java execution default initialization program:

*
* Thinking in Java Test 2.1
* @author: Wolfofsiberian */public
class tij_test2_1{
	Boolean B;
	int i;
	char c;
	
	public static void Main (string[] args) {
		tij_test2_1 test=new tij_test2_1 ();
		System.out.println ("Boolean B is:" +test.b);		
		System.out.println ("Integer i is:" +test.i);		
		if ('% ' = = test.c && ' \u0000 ' ==test.c && ' = = ' = ' \u0000 ')
		System.out.print ("Character C is:" + test.c+ "!");
	}


Execution results:


Boolean b Is:false
Integer I is:0
Character C is:.

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.