Java from small white to getting started, Day6. javaoo-Package

Source: Internet
Author: User

Encapsulation is the process and data is surrounded, access to data only through the interface defined. Object-oriented computing begins with this basic concept that the real world can be portrayed as a series of fully autonomous, encapsulated objects that access other objects through a protected interface. Encapsulation is an information hiding technology that is encapsulated in Java through the keyword private. What is encapsulation? Encapsulation combines all the components of an object, encapsulates the data that defines how the program references the object, encapsulates the fact that it hides the data of the class, and controls how much the user modifies the class and accesses the data.

Encapsulation is to hide internal implementations and expose access interfaces.

Access modifier: Used to control access rights to resources (default,public,private,protected);

Default: Package access, resources that are decorated with it can only be accessed in the same package.

Public: Publicly accessible, resources that are decorated with it can be accessed at any location.

Private: A resource that is decorated with it can be accessed only in that class.

Protected: Protected Access, which can be accessed by all classes in the same package, or by a quilt class, regardless of which package the subclass is in.

The access modifiers of the class can use only default and public. The access modifier for a property can use either.

Access with Get and set accessors: All class properties are private, allowing eclipse's functionality to implement get and set accessors. In set, the control value is taken. All other places use accessors to read or set. The settings are all in set, and the values are all taken in the get.

    • For Exampl
    • public class Book {

      Private String BookName;

      Public String Getbookname () {
      return bookname;
      }

      public void Setbookname (String bookname) {
      This.bookname = BookName;
      }

      }

    • This enables a package effect.

Java from small white to getting started, Day6. javaoo-Package

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.