public Class Pet
{
public Pet()
{
// default constructor code
}
public Pet(String name)}
{
// call the default constructor
this();
}
I found this syntax to be a little strange. Yes I understand the “this” keyword refers to the current object. But we are talking about making a call to a method in the class. Why not use the name of the method like so:
public Class Pet
{
public Pet()
{
// default constructor code
}
public Pet(String name)}
{
Pet(); // This does not work!
}
It seems logical to use the actual method name when making a call to it. However the Java designers must not have agreed with me. Calling the constructor by its name results in a compile time error. Oh well. It was worth a try.