It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Constructor doubt - K&B 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 "Constructor doubt - K&B Book" Watch "Constructor doubt - K&B Book" New topic

Constructor doubt - K&B Book

Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
Hi all,
This is reference from chapter 5 Kathy and Bert book pg 325. Look at the code below.

The explanation given in the book says that some compiler might give error and sometime JVM could throw StackOverFlowError. I tried this code and I am getting compile time error saying "recursive constructor invocation".

My question is what should we select in the exam if we have both the options
a) Compile time error
b) Run-time error.

Any thoughts/suggestions ?


Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
Joe Borderi
Ranch Hand

Joined: Oct 23, 2004
Posts: 151
You may see this as punting, but I really wouldn't worry about this question on the exam. Questions on the exam are very well tested and unambiguous. If the book gives you a question with "sometimes the answer is this... and sometimes the answer is that... " answer, the question won't be on the exam.

As a programmer, you should simply know and understand that the situation depicted in the question is something you don't want to do.
Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1850

This constructor is recursive.

Krishna Srinivasan
OCAJP 7/8 Exam, 400+ OCPJP Mock Questions
I agree. Here's the link:
subject: Constructor doubt - K&B Book
It's not a secret anymore!