+ 1
what size does memory use while we declare a class
3 Answers
+ 1
The class itself requires no space in memory of a running program. The class in the source code of course requires the size determined by the source code length (number of characters) and the charset encoding (e.g. UTF-8, UTF-16, UTF-32 etc.).
A class *instance* (even an empty one with no fields and functions) takes up at least one byte.
The specific size a class instance required in memory depends on the number and size of the fields, the memory allocated dynamically and the a number memory alignment switches of the compiler.
0
size is depend on variables which we take in class of different data types
0
When your program is compiled and then executed, only functions of the class will be placed in memory (data segment I believe). The size of the function depends on the amount of assembly instructions it generates at compilation. Then later on during run time an object can either be stored in the stack or heap (depending on how it's instantiated). When it is stored in the stack/heap, only the instance variables will be stored, and the size depends on the data types of the instance variables (which will simply be summed together).