Java constructor Problems

Source: Internet
Author: User

a Java class has two constructors, why use this when another constructor is called in one constructor. () and cannot use the class name. ()

If there is a parameter type, if the type is exactly the same then it is not possible, only a different name.
method overloading refers to defining multiple methods with the same name in a class, but requiring each method to have a different number of types or parameters. When calling an overloaded method, the Java compiler can choose an appropriate method by checking the parameter type and number of the called method. Method overloads are typically used to create a method that accomplishes a similar set of tasks but differs in the number of types or parameters of a parameter. Method overloading is a means for a class to handle different types of data in a uniform manner. Java's method overloading is that you can create multiple methods in a class that have the same name but have different parameters and different definitions. Methods are invoked by the different number and type of arguments passed to them to determine which method to use
For example:
Public void Demo (String a1,int a2) {}
Public void Demo (int a1,string A2) {}
this can
Public void Demo (String a1,string a2) {}
Public void Demo (String a2,string A1) {}
This will be an error .

This article is from the "Java White Battlefield" blog, be sure to keep this source http://8023java.blog.51cto.com/10117207/1766232

Java constructor Problems

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.