could anyone please explain that if i make 1000s of instances of the same class then how will the memory be allocated to the instances of the class( i mean to diffent parts of the class i.e methods and attributes ) ...... please help !!!
i mean to diffent parts of the class i.e methods and attributes
The size of an object of a class depends on the instance fields. Methods don't occupy memory in a class object (as far as I know). static fields also are shared among instances of a class. so they also don't occupy memory in individual objects of a class.
if my class takes 1 mb of memory in total
if an object of your class occupies 1mb, then 10 objects will occupy 10 mb memory.
Yes, that's true. 10mb, according to your example, would be the memory used for the objects of your class because each object would be using its own space over the heap. But then taht 1mb should be the memory taken by the object, apart of the loaded class.