• Post Reply Bookmark Topic Watch Topic
  • New Topic

Memory allocation  RSS feed

 
Dhinesh babu
Greenhorn
Posts: 15
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Consider the following code



If i create an object for the above code using new keyword, how the memory willbe allocated in heap.
Please explain

Thanks in advance,
Dhinesh
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your example code is malformed, it will not compile. You are missing a closing } for the main method. Did you mean a and b to be local variables in the main method?

When you create an object, some memory will be allocated on the heap to store the member variables and some other data for the object. Assuming that a and b are local variables inside the main method and not member variables, your class doesn't have any member variables, so the object will consist of just a few bytes with some administrative information that the JVM uses internally.

Was that what you wanted to know? If not, then please explain your question in more detail.
 
Dhinesh babu
Greenhorn
Posts: 15
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Yes. This is what i needed. Thanks.

Dhinesh.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!