Sen, The first example has a default constructor. If you don't type any constructors in a class, Java provides one without any arguments automatically. If you type in a constructor of your own, Java doesn't add a default one.
Note that in the second example, you could use "super" to force the provided constructor to be called. This would prevent the compiler from looking for a non arguments constructor.
Unless a constructor contains an explicit call to "super" or "this" as its first line, there is an implicit call to super with no arguments. So in both of your examples, the subclass constructor is implicitly calling super() with no arguments.
If no constructors are defined for a class, the compiler automatically inserts a default no-args constructor.
In your first code example, there are no superclass constructors defined, so the compiler inserts a no-args constructor. Then when the subclass calls super(), it works fine. But in your second code example, your superclass has a constructor defined that takes a String argument, so the compiler does not automatically insert a no-args constructor. Therefore, the subclass call to super() will fail unless you explicitly define a no-args constructor in the superclass.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Sep 21, 2005
Thank you both for the insights. The doubt is cleared.