+ 1

Why the size of empty class is 1 byte but the size of empty structure is 0 bytes

8th Jan 2017, 5:36 AM
Saksham Jain
Saksham Jain - avatar
3 odpowiedzi
+ 2
because every class extends from Object, so they have ther methods, like "toString()" , or "equals(obj)"
8th Jan 2017, 5:43 AM
Nahuel
Nahuel - avatar
0
sorry not understood.Could u please elaborate
8th Jan 2017, 5:43 AM
Saksham Jain
Saksham Jain - avatar
0
A class is instantiated only when you create a new object to it(even though the class is empty). There by when a new object is created to the empty class the compiler assigns address for that, address stored in memory occupies 1 byte. Therefore the sizeof an empty class will be atleast 1 byte
11th Jan 2017, 8:12 AM
Sai Krish
Sai Krish - avatar