Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in output of the program

 
Jyothsna Panchagnula
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Source:http://www.go4java.20m.com/mock1.htm


Why is the output of the program not recursive?
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jyothsna,

What makes you think there is recursion in the code? The method abc() doesn't call itself anywhere directly or indirectly.
 
geeta vemula
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then what is the correct output? I think its option 4.Is it right?

Thanks,
Geeta.v
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it should output 0. You are not initializing the static variable, but the shadowing local variable.
 
Shwetha Sharma
Ranch Hand
Posts: 34
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You are not initializing the static variable, but the shadowing local variable.


Hi Rubin,
what do you mean by the above statement?
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shweta S Sharma S:


Hi Rubin,
what do you mean by the above statement?

Hi Shweta,

Sorry for the misunderstanding, this is my mistake. I misread the static variable declaration and I thought its name was i as well.
:roll:
There is no shadowing going on because the static variable has a different name.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic