Member Avatar for Rahul47

When we create an object how much memory will be allocated to it ? Is memory allocated for methods too ? If Yes, How ?

Recommended Answers

All 3 Replies

Beuase all the methods are the same, there's just one copy in memory. That's loaded when the class is loaded ie sometime before you first use it. The same is true of static variables.
Memory for instances of classes is created when the instance is created - that's a few bytes for the instance, plus enough for each of the instance variables.
Exactly how much memory. and exactly how it is allocated is private to each implementation of the Java Virtual Machine (JVM).

Member Avatar for Rahul47

What kind of allocation is done ? Stack, Heap, Queue ?

Classes and instances are all allocated on a JVM heap. Parameters and local variables in methods are allocated on the stack.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.