On page 315,rules for the constructor, it states " Every constructor must have as its first statement either a call to an overloaded constructor( this()) or a call to the superclass constructor ( super())." According to me, this need not be done explicitly. If we dont write explicitly, the compiler will anyway call the default constructor from the superclass. I think should state as, " Every Constructor will have ...."
You can interpret that line however you'd like. The rules of Java state that every constructor must invoke another constructor within the class or the constructor of the parent class. If you don't provide the invocation, the compiler will do it for you. Take a look at the JLS §8.8.5 Constructor Body for all sorts of good details. Hope that helps, Corey
I agree with you all but I think the wording is incorrect. I think that statement means that when a programmer writes constructors, he/she must either add this() or super() as first statement. But thats just my opinion... Jyothy [ March 25, 2003: Message edited by: Jyothy kidambhi ]
Joined: Dec 20, 2001
Originally posted by Jyothy kidambhi: I agree with you all but I think the wording is incorrect. I think that statement means that when a programmer writes constructors, he/she must either add this() or super() as first statement. But thats just my opinion...
Obviously, we're to the point now where we're splitting hairs. You understand perfectly well the concept here, that the constructor must invoke another constructor, whether it is done by the programmer or done implicitly by the compiler. I'm sure it could have been worded differently in the book, but notice that the statement says:
Every constructor must have as its first statement...
It does not say:
The programmer must insert a call as the first statement to...
As I said, we're really just splitting hairs here. If you want to interpret it one way or the other, fine.
Hey Jyothy - The section of the book you are referring to is a summary section. Your point is accurate, and we discuss this topic in detail in this chapter. So when you're reading a 'summary' section you have realize that it's a summary - we can't replicate the entire JLS in every summary, then it wouldn't be a summary -Bert
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)