Differences between the Java constructor and the Void method

Source: Internet
Author: User

The void type method does not return anything, but it is your decision, and you can let it return something. And the constructor doesn't return anything, and you have no choice. " ----This sentence means that you decide to let this method return a void type, and you can also change it so that it does not return void and return other types such as int,string. But for the construction method you have no chance to decide what the return type is.

the constructor is an unusual type of  method because it has no return value. this is distinctly  different from a void return value, in which the method  Returns nothing but you still have the option to make it  return something else. constructors return nothing and you don ' t  have an option.

The process of creating an object when the constructor opens up memory space in the heap. If a method uses the constructor to create an object, the object address is returned. Accept this object address with a parameter, which is a rule that cannot write the return value.

such as Student s = new Student ();

The normal method can be selected regardless of whether the return void or string is the object. And the constructor is absolutely not.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Differences between the Java constructor and the Void method

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.