my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in kathy- Bert's book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in kathy- Bert Watch "doubt in kathy- Bert New topic
Author

doubt in kathy- Bert's book

shalini sharma
Greenhorn

Joined: Nov 21, 2002
Posts: 26
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

Joined: May 05, 2000
Posts: 13974
You are correct in that you do not have to explicity code: super() as the first instruction in your constructors.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
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


SCJP Tipline, etc.
shalini sharma
Greenhorn

Joined: Nov 21, 2002
Posts: 26
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

Joined: Dec 20, 2001
Posts: 3271
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

Joined: Oct 14, 2002
Posts: 8803
    
    5
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.)
 
 
subject: doubt in kathy- Bert's book
 
Similar Threads
extending a class
constructor question
constructor
Constructor usage in superclasses
Question regarding Inheritance