logical structure/details of a reference variable and object in the memory?

后端 未结 4 1308
囚心锁ツ
囚心锁ツ 2021-02-09 11:47

Let\'s say we have a class:

class Class1
{
   int i = 1;
}

and we have a variable:

Class1 ob1 = new Class1();
4条回答
  •  清歌不尽
    2021-02-09 12:02

    Answering your question:

    1. No, it doesn't. Reference is just a reference, i.e. some address in heap, where corresponding object is stored. There is no need to store duplicate information about reference type in reference itself, because actually real variable, which contains its reference address could be of various class types.

    2. Very strange question. Of course, yes, it does. Furthermore, this "part of heap" is an object, which contains this particular class description. Any Class object contains information about full name of that class, which is described by it.

    3. It is not defined as how it looks logically, if you mean its structure:

    2.7 Representation of Objects:

    The Java virtual machine does not mandate any particular internal structure for objects.

    But if we are talking about information about class type - yes, it is just a String object, because "type" of Class object (which it is represent) is just a name of corresponding class.

提交回复
热议问题