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)