• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help me understanding this

 
Mani Sing
Greenhorn
Posts: 7
Linux Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Redwood extends Tree{
public static void main(String [] args){
new Redwood().go();
}
void go(){
go2(new Tree(),new Redwood());
go2((Redwood) new Tree(), new Redwood());
}
void go2(Tree t1, Redwood r1){
Redwood r2=(Redwood)t1;
Tree t2=(Tree)r1;
}
}
class Tree{}


I mean how the stack and heap will contain the different references as well as objects.

Will appreciate your help in this.
Thanks

 
Sunny Bhandari
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags and do ask more specific question.

I mean you must have got some idea what is stored in stack and what in heap!!
 
Harshit Rastogi
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objects created by new operator and global variables are stored in heap..

All local variables created inside methods are stored in stack...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic