Java-4.3 default constructor
In this section, we will discuss some notes about the default constructor and this.
1. default constructor
When you do not set any constructor, the system creates one by default.
Package com. ray. ch01; public class Test {}
The code above actually contains a non-argument constructor by default. In this case, you can use new Test () to create an object.
However, if you have defined some constructors and do not use the non-argument constructor, you cannot create them using new Test (), because the system defines them by default, no longer added by default.
Package com. ray. ch01; public class Test {public Test (int I) {} public static void main (String [] args) {new Test (); // error new Test (1 ); // correct }}
Copy the above error code and run it on your own to know the result.
Summary: This chapter briefly discusses some notes about the default constructor (no-argument constructor.
This chapter is here. Thank you.