I wanted to know if non-static methods are duplicated in objects, if you create 1000 objects, you get a copy of this method in each object

  • Of course nothing is duplicated. Otherwise, no methods will be saved for each instance - DreamChild

1 answer 1

The code of class methods (both static and non-static) is always * stored in a single copy, regardless of the number of objects created. For each object, only memory is allocated for data - the value of the class fields.

* This statement may be incorrect if the code of the same class is loaded by several classloaders. In this case, the code is duplicated, but the classes loaded by different classloaders are considered different, even if they were loaded from the same .class file.