Java Classes and objects

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.