The moose likes Java in General and the fly likes object size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "object size" Watch "object size" New topic

object size

lalit mohan

Joined: Apr 08, 2004
Posts: 16
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

Joined: Mar 18, 2004
Posts: 572
It will not take any bytes in memory
Carlos Failde
Ranch Hand

Joined: Oct 20, 2000
Posts: 84
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.
I agree. Here's the link:
subject: object size
It's not a secret anymore!