Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

object size

 
lalit mohan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends,
if i have a class with no variable declaration and method
and i have a object of that class. then but will be size of that object.
there is any method for obtain the size of object.
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will not take any bytes in memory
 
Carlos Failde
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An empty class with no fields must still extend another class. Say it extends object, it will inherit the methods of the Object class so must have a non-zero size.
There has been discussion on JavaWorld about object size such as Sizeof for Java. Playing around with the example program listed in that article suggests that an empty instance just like an object instance occupies eight bytes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic