• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Core Java

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




Please post output with reason...
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sagar. Welcome to The Ranch!

It'll be a more effective learning experience if you try it yourself first. What do you think it will output? Or, try compiling and running it yourself. If you don't understand why it does what it does, come back to us and we can help you.
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is it legitimate to initialize a same object twice in a program within a same class ?? besides the object is calling itself it will be a stack overflow error.

I am too not sure about this. I changed the name of the objects, put them as three different objects then also there is a stack overflow error. Seniors please reply.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't initialise the same object twice. You can initialise numerous instances of the same class, but they are different objects.

Write down some diagrams like those in this post, only you label the boxes t and t1 and t.t and t1.t etc etc. Then you can predict whether you will overflow your stack or not. As the chap who posted that older post said, pencil and paper and eraser. That's what you need to use
reply
    Bookmark Topic Watch Topic
  • New Topic