• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Core Java

 
sagar sinha sagar
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




Please post output with reason...
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
shivang sarawagi
Ranch Hand
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47222
52
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic