Object-oriented learning of Java Tutorials (iv)

Source: Internet
Author: User

Learn to program the Java tutorial Object-oriented (iv) published, Welcome to visit through the xuebiancheng8.com

This session is to analyze the Java object-oriented construction method. What is the construction method, the construction method is called by the name, the construction of the time to execute the method call the construction method.

Yes, the construction method is to construct the object when the method is executed, that is, the construction method, when the object is constructed, is not in the new time to call the construction object, so the construction method is the new object execution method is the constructor method. Construction methods are typically used to assign an initial value to an object. Completes initialization of the object.

Let's look at how to define a construction method.

public class person{

private String name;

private int age;

Person () {

System.out.println ("Execution construction method");

}

}

As above, a constructor method is defined, with the name of the constructor being the same as the class name and no return value.

When we execute person p = new person (), the constructor of person () is called.

The output executes the construction method.

For more information, please visit xuebiancheng8.com

The specific URL is

Http://xuebiancheng8.com/play/goodgoodstudy_94_daydayup.html


Object-oriented learning of Java Tutorials (iv)

Related Article

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.