This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Plz . Answer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Plz . Answer" Watch "Plz . Answer" New topic
Author

Plz . Answer

faisal usmani
Ranch Hand

Joined: Jan 14, 2006
Posts: 139
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
faisal usmani
Ranch Hand

Joined: Jan 14, 2006
Posts: 139
Thanks sir
I got the point
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Plz . Answer
 
Similar Threads
Beginner in servlets
protected member access
Are my answers correct ?
How to know a class is Immutable or Not
Mughal Mock Exam Doubt.