Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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

Recursive constructor invocation

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have the following code:



I am using "javac 1.5.0_06". The compiler spits out the following error:
TestThis.java:9: recursive constructor invocation
public Dummy( String d ){
^
1 error


The excerpt from book "SCJP 5 Study Guide" is "your compiler may not actually catch the problem (it varies depending on your compiler, but most won't catch the problem).

for the following code:



It compiles fine, of course runtime error.

Who shall we listen to for the recursive constructors case during the exam? Select it compiles, or select its compilation fails?

THanks.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there would be one more option in the exam ... depends on the VM
 
warren li
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Akash Bhatt:
there would be one more option in the exam ... depends on the VM



 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi warren

Compiler catches the recursive constructor call because at the compiler time it checks the way to reach the parentclass(in our case Object class).

Compiler automatically adds super in the first line of the every Constructor (provided we aren't given and this() is not in the first line of the constructor)

So in our case it cannot add super in both of the constructor because this() is present in the first line. so it throws error.

But in case of method,
Compiler just checks for syntax and other stuff(not a flow).

Correct me if i am wrong
 
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving 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