Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Steve
No, it doesn’t. It calls a no-arguments constructor. A default constructor is a no-arguments constructor, but a no-arguments constructor is not necessarily a default constructor.Anayonkar Shivalkar wrote: . . . a constructor always calls a default constructor of super class. . . .
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Similarly, you have class Name1 extends Item1, which says that every Name1 IS-A Item1, by by extension because in your code an Infant IS-A Name1, then Infant IS-A Item1. Are your Infants for sale? Name1 should not extend Item1, and Infant should not extend Name1. Rather, Infant should have instance variable which hold the Name1 and Item1 which you want to associate with the Infant.
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Anayonkar Shivalkar wrote:You are welcome.
However, I'm still wondering, how did you get runtime exception? I got compile time error itself.
@Campbell Ritchie, thanks for the 'no-arg constructor' correction.
Brad Edwards wrote:The reason why I couldn't do this though was because the instructor wanted us to make a class an inheritance of two other classes and be able to call the parent classes from the subclass.
Steve
No, you are simply hiding other potential errors from yourself. A constructor should initialise the class by establishing its invariant. By writing a no-arguments constructor you are saying you permit different Items, all with the same description price and number, possibly . What you ought to do is delete that no-args constructor and always call the existing constructor from the sub-class constructor. Assuming the Item constructor is the same as in your first post, your Name1 constructor should look like this: . . . which shows how to call a superclass’ constructor to establish its invariant correctly.Brad Edwards wrote: . . . I put in the no-arg constructors that I needed and it works great. . . .
Well done . . . and “you’re welcome”.Brad Edwards wrote:ok, I understand... Thanks
Do Re Mi Fa So La Tiny Ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|