This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Where reference variables stored ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Where reference variables stored ?" Watch "Where reference variables stored ?" New topic
Author

Where reference variables stored ?

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
hi all
if we have a code like this
class chk
{
chk c=new chk();
void disp()
{
......
}
where the reference variable which is declared here as instance will get stored ?

thanks


Anto Telvin Mathew<br />Many of the life failures are people who did not realize how close they were to success when they give up. EDISON
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

On the heap.

Your code is a StackOverFlowError waiting to happen though.

You class "chk" has a field of the same type. You initialize that immediately. Therefore, the following will happen:
- you create chk #1
- this will automatically create chk #2
- this will automatically create chk #3
- this will automatically create chk #4
- this will automatically create chk #5
...

This will continue on forever - until the error is thrown.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
thanks
 
jQuery in Action, 2nd edition
 
subject: Where reference variables stored ?
 
Similar Threads
The Java Virtual Machine has exited with a code of 1, the service is being stopped.
Where are these java ...... etc stored
Object and Varaible
[B] a private final method can be overridden!!!! [/B]
Printing ArrayLists