S
S
Safarsky2019-03-26 23:08:52
Java
Safarsky, 2019-03-26 23:08:52

Are the fields of the object placed on the heap, or are its methods too?

Hello.
They say that objects are placed on the heap. Do you mean its fields or also methods?
That is, methods are created for each object, or do all objects of the same type refer to the same methods?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2019-03-26
@Safarsky

The data is placed on the heap.
Methods are not data.

S
Sergey Gornostaev, 2019-03-27
@sergey-gornostaev

Method bytecode is in classes, classes are in metaspace, and metaspace is off-heap. Objects are normal C structures containing nothing but field values ​​and a 16-byte concatenation for a header. You might be interested in this answer .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question