Home > Back-end >  In the code below I delete a no-parameter constructor, can run normally, which bosses know can have
In the code below I delete a no-parameter constructor, can run normally, which bosses know can have

Time:09-24

Public class BorrowABook
{
Public BorrowABook ()
{
}

Public void Borrow (String name)
{
System. The out. Println (" please to lending registration "+ name +", ");
}
Public static void main (String [] args)
{
BorrowABook book=new BorrowABook ();
The book, Borrow (" "war and peace" ");
}
}

CodePudding user response:

When there is no constructor class, compile with no arguments structure by default

CodePudding user response:

Has no effect, don't write a no-parameter constructor will have default any constructor, but if you added a parameter of the constructor, need to manually make up a no-parameter constructor

CodePudding user response:

When you didn't write a constructor, the compiler will help you to provide the class by default no arguments constructor; If you write the constructor, either have or no parameters, the compiler will not provide a default structure, so, you write above, when you delete the writing your own no arguments constructor, the compiler is to provide a no arguments will help you the default constructor, so does not have any effect, but if you wrote a no-parameter constructor, have deleted, no arguments constructor you wrote is the Main method of creating objects will compile error, suggest you don't have a no-parameter constructor or need to write parameters, and remember,,,,,
  • Related