Static fields and methods are allocated memory once only, when they are first referenced, irrespective of the no. of objects u later create. But, memory is allocated for its data members each time an object is created. But what about the non-static methods, they don't change for each object. So are they allocated memory once for all objects or once for each object ?

Recommended Answers

All 2 Replies

Depends on the JVM implementation.

Methods, both static and instance, are loaded into the VM when the class is loaded. Only one copy of each method is loaded and held in memory.

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.