1 in-memory objects
When a variable is declared in a class, it is either at the class level or at the method level. When the program runs, it allocates memory to the RAM, which is logically divided into stacks and heaps (heap), the base type is allocated on the stack, and the Java objects are allocated in the heap area. When declaring a reference variable, memory does not contain object data, and contains only the address of the object in the heap.
An object can be referenced by more than one reference variable, which is equivalent to a different reference variable pointing to the same address in the heap
For example:
1 Book book1=new book (); 2 Book book2=Book1;
At this point book1,book2 points to the same address.
1 book Book1=new book (); 2 book Book2=new book ();
The heap assigns different regions to the objects referenced by the BOOK1,BOOK2
2 Package and access control
Class and class members have public protected the different access control types in the default private four, the three main features of OOP programming are encapsulation inheritance polymorphism, where access control ensures data security access. The following table lists the Java class member access control levels, which are similar to class access level control
Java Classes and objects