This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Core Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Core Java" Watch "Core Java" New topic
Author

Core Java

sagar sinha sagar
Greenhorn

Joined: Aug 13, 2009
Posts: 1




Please post output with reason...
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4344
    
    8

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

Joined: Jun 19, 2008
Posts: 147
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

Joined: Oct 13, 2005
Posts: 38075
    
  22
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
 
Don't get me started about those stupid light bulbs.
 
subject: Core Java
 
Similar Threads
Calling one constructor from another
Adding JScrollPane to JPanel?
Garbage Collector
Java Interface
Garbage Collection