File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constructor question

 
Sumanth Shanbhag
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This question is straight from the KS&BB book.



I don't quite understand how the compilation fails as explained by the author. In Bottom2 the super() would be called, which would be a no-arg constructor to its parent class Top. But since Bottom2's constructor is already overridden with arguments matching the super class constructor there shouldn't be a problem with compilation at least. Correct me if i am wrong here please..
 
Mercurio Savedra
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friend, remember that if you dont write an explicit call to the super constructor with some arguments the compiler try to insert at he first line of the constructor a super no arg call, then reviewing the parent class there is not a no arg constructor so the compilaton process fail

got it?
 
Meena R. Krishnan
Ranch Hand
Posts: 178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add "super(s);' as the first line of Bottom2's constructor and it will compile fine.
 
Michael Raymond Jr.
Ranch Hand
Posts: 178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think in the K&B book they recommend to always create the default constructor if you are overloading it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic