CS202 Java-77
Constructors in Hierarchies
lDefault constructors for base classes are implicitly invoked from the derived class’ constructor
•As with C++, from the base class “outward”
lHowever, when we have constructors with arguments, this gets more complex (but of course is handled differently than C++!)
•In Java, we must explicitly write the calls to the base class constructor using the super keyword, followed by the appropriate arguments:
•This must be the first thing that is done in your derived class constructor
•Luckily, Java will complain if you don’t do this! Unlike C++.
•
•public class ordered_list extends list {
•ordered_list(int i) {
•super(i); //causes base class constructor with an int to be called