This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in K&B pg:167,Q:7 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in K&B pg:167,Q:7" Watch "Doubt in K&B pg:167,Q:7" New topic

Doubt in K&B pg:167,Q:7

Sekhar Choudary
Ranch Hand

Joined: May 03, 2008
Posts: 57
there is a question in K&B book that asks for inserting code that will make the program compile successfully.
Usaully, we can do the program to compile in two ways, this means, in two ways we can fix the code.

but according to KB book, th answer is like this

class AgedP{
AgedP(){ }
public AgedP(int x){
public class kinder extends AgedP{
public kinder(int x){ super(); }

But the following will also result in compilation successful, regardless of runtime exceptions(since the question is to make sure the program compile successfully.)

class AgedP{
AgedP(){ }
public AgedP(int x){ this(); //Newly inserted statement
public class kinder extends AgedP{
public kinder(int x){ super(); }

This will also compile successfully.

Which to select.

Harshit Rastogi
Ranch Hand

Joined: Apr 15, 2008
Posts: 131
can you paste what is the original code in the question ?

My Techie Blog - Java Questions
Ga�lle Fournier

Joined: Jul 26, 2008
Posts: 5
I remember this question. I actually gave the answer with the "this();" statement.

It didn't phase me at the time because I wrongly read in my head "Fragments: Use the following fragments zero or one times". But looking back, it seems to me that the answer with the statement "this();" added is also correct bescause it actually says "Fragments: Use the following fragments zero or more times".

I would also like to know if it is correct or not.

PS : is it legal to post the question ?
[ July 26, 2008: Message edited by: Ga�lle Fournier ]

I agree. Here's the link:
subject: Doubt in K&B pg:167,Q:7
jQuery in Action, 3rd edition