Two Laptop Bag*
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 Android Security Essentials Live Lessons 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
Author

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

Sekhar Choudary
Ranch Hand

Joined: May 03, 2008
Posts: 57
HI,
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.

Thanks.
Harshit Rastogi
Ranch Hand

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


<a href="http://technologiquepanorama.wordpress.com" target="_blank" rel="nofollow">My Techie Blog</a><br /><a href="http://www.java-questions.com" target="_blank" rel="nofollow">Java Questions</a>
Ga�lle Fournier
Greenhorn

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 ]

SCJP 6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in K&B pg:167,Q:7
 
Similar Threads
K&B SCJP 5...Chap2..Que 7
SCJP Study Guide 6 question
"Complete the following so it compiles" - anything that compiles or the smallest bunch of code?
K&B 5.0, Chapter 2, Question 7, Drag N Drop
Not convinced with K&B solution for couple of questions, please help