Nikhil Agrawal
Nikhil Agrawal

Reputation: 26548

Does java object class has any variables inside it apart from methods

Actually till date What I know about java object class is it has methods like we have clone(), toString() but somebody told me it contains variables also. So what are those variables. Went through google. Does anybody know anything which variable it contains.

Upvotes: 0

Views: 70

Answers (2)

Akash Yadav
Akash Yadav

Reputation: 2421

Java Object doesn't have any fields. You can see the source yourself to validate.

But yes whenever an object is created , a monitor is also created alongside to handle the locking on that object. Similarly jvm keeps a track of number of threads requesting lock on the object, these variable are not part of java object, but associated. I guess the interviewer was hinting at those.

Read this for More on Monitor

Upvotes: 1

Steve Chaloner
Steve Chaloner

Reputation: 8202

It doesn't contain any fields. You should be able to open the source code from your Java installation and confirm this for yourself.

Upvotes: 1

Related Questions