• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Memory allocation

 
Greenhorn
Posts: 15
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Yes. This is what i needed. Thanks.

Dhinesh.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic