File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where reference variables stored ?

 
Anto Telvin
Ranch Hand
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anto Telvin
Ranch Hand
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic