Java void keyword __java

Source: Internet
Author: User
Overview

Void is a keyword in Java, often encountered in daily development, the Java Main method is defined in the form of void, as follows:

public static void Main (string[] args) {

}

People who have studied Java know that void means empty, and if you ask an old hand, an old hand will tell you, "Void is nothing, you just remember void is empty, and when the method is stated, the method has no return value". what void is.

The Java language is strongly typed (strong typed), from the syntax of the method declaration, you can see that the definition of the method must have a return value, the type of the method return value needs to be determined, and when the method definition is void decorated with no return value, then void should be considered a data type. In Java, there are only two types of data, the basic data type and the reference data type, and the basic data types (8 types) are as follows:

Data Type type Packing class
Basic type Byte Java.lang.Byte
Basic type Short Java.lang.Short
Basic type Int Java.lang.Integer
Basic type Long Java.lang.Long
Basic type Float Java.lang.Float
Basic type Double Java.lang.Double
Basic type Char Java.lang.Character
Basic type Boolean Java.lang.Boolean


Reference type:
Include class, collection collection class, custom class, and so on.

So what are the types of void in Java?
In fact, Void also has a corresponding wrapper class java.lang.Void, but we cannot directly operate on them. It inherits from object, as follows:

Public final class Void extends Object {
    /
     * * The Void class cannot be instantiated.
     * *
    Private Void () {}
}

The void class, like the string class, is defined as final, so it cannot be extended; In addition, its construction method is privatized so it cannot be instantiated.

A void class is a placeholder class that is not instantiated to hold a reference to a class object that represents the Java keyword void.

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.