Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in kathy- Bert's book

 
shalini sharma
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...."

Correct me If I am wrong...
Regards
Jyothy
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct in that you do not have to explicity code: super() as the first instruction in your constructors.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
shalini sharma
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic