If I have a classes A_1, … A_m extending a class B, then the size of an object of A_i is at least the size of an object of B.
If I now declare an array
B collB[] = new B[1];
then how much space is allocated?
Thank you
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That’s creating an array with one element. It’ll probably be about 20 bytes, and will vary depending on the JVM you’re using (e.g. 32-bit vs 64-bit).
It won’t vary at all by the number of fields in
B, orA, or anything like that – because you’re not actually creating any instances ofB. You’re only creating an array, whose sole element will be a null reference initially.