• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Plz . Answer

 
faisal usmani
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the size of an object in Java , if the class has no member variables or member functions .

Eg :-

class ABC
{

}

What will be the size of object of class ABC if we do

ABC ob1 = new ABC();


Do we have a sizeof operator in Java as we have in C/C++
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The actual amount of memory that an object uses depends on the Java implementation -- i.e., it's not specified by the Java VM specification or the Java Language specification. The number is never directly useful in any program -- no Java language function or construct depends on the memory image size of an object. The precise answer may well vary by JVM vendor, by platform, and even by version.

That said, for Sun's JVMs a good rule of thumb is 16 bytes for an object, plus four bytes for each member -- except doubles and longs, which are 8 bytes each.

Note: have a look at this when you have time.
 
faisal usmani
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks sir
I got the point
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic