Here's the common syntax for creating an object in Java:
Puppy myPuppy = new Puppy( "tommy" );
According to this description of Java classes on TutorialsPoint, the components of this syntax are as follows:
Declaration − A variable declaration with a variable name with an object type.
Instantiation − The 'new' keyword is used to create the object.
Initialization − The 'new' keyword is followed by a call to a constructor. This call initializes the new object.
And according to this Quora article, constructors must have the same name as the class they belong to.
However, I sometimes see Java objects being created where the constructor part of the syntax differs from the class name, like so:
Dog myDog = new Puppy( "tommy" );
I don't understand how the above syntax can be valid. What is it doing? What type of class is myPuppy?
EDIT: Sorry - to make this clearer I have flipped the Dog / Puppy references in that last line of code, as it makes more logical sense for a Puppy class to extend a Dog class.