• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

doubt in kathy- Bert's book

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 9034
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic