Default builder

xiaoxiao2021-03-06  43

The default builder is no argument. Their role is to create an "empty object". If you create a class without a builder, the compiler will help us automatically create a default builder.

Class bird {

INT I;

}

public

Class defaultconstructor {

public

Static

Void main (string [] args) {

Bird nc =

NEW bird ();

// default!

}

For the following line:

NEW bird ();

Its role is to create a new object and call the default builder - even if there is not clearly defined a builder like this. If there is no, there is no way to call, and our object cannot be constructed. However, if a builder has been defined (whether or not there is a variety of variables), the compiler will not help us automatically synthesize:

Class bush {

Bush (INT I) {}

Bush (double d) {}

}

Now, if you use the following code:

New bush ();

The compiler will report that you can't find a constructed builder. Just as we have no builder, the compiler will say: "You seem to need a builder, so let us create one." But if we wrote a builder, the compiler will say: "Ah, you have written a builder, so I know what you want; if you don't place a default, it is because you intend to omit it."

转载请注明原文地址:https://www.9cbs.com/read-55731.html

New Post(0)