The text in the book i am reading states in summary
“Technically, constructors cannot be overidden because they have same name as the current class. New constructors are created instead of being inherited. This system works fine;…”
The part I don’t understand is when they say this:
“when your class’s constuctor methods are called, the constructor methods with the same signature for all your superclasses are also called . Therefore, initialization can happen for all parts of a class you inherit”
What I don’t understand is the same signature section…. It comes accross to me as though all the constructors must have the same signature, and then when you initialize a child class object all it’s super classes will automatically be called instead of having to call super(arg1,arg2) for each sub class…. Is this what they are stating?
This is incorrect. First, a note on terminology: constructors are not methods, so the term “constructor methods” does not make any sense.
While it is true that a super class constructor is invoked, it needn’t have the same signature. If a subclass constructor begins with a super class constructor invocation expression such as
the superclass constructor matching the argument count and types in invoked. You are completely free which arguments you pass to that constructor.
If the subclass constructor does not begin with a super constructor invocation expression, the compiler will insert a call to the accessible zero-argument constructor of the superclass for you – or raise a compilation error if there is no such constructor.
You are aware that Java 2 is a decade out of date? Any book this old will teach you obsolete stuff, that you would be best served to forget quickly. Why not use a more modern book?