Anonymous object, encapsulation (private), this keyword, construction method

Source: Internet
Author: User

1. Anonymous objects
    • Anonymous object: An object without a name
    • Application Scenario: Call the method, only once, the anonymous object can be passed as the actual parameter
      ?? Example: New Student (). name;2. Encapsulation (private)
    • Encapsulation Overview: Refers to the properties of hidden objects and implementation details, only provide public access to external
    • Benefits: Hides the implementation details to provide public access, improves code reusability, and improves security
    • Principle: Hide content that does not need to be provided externally. Hides the property and provides a public way to access it.
    • Private keyword Features
      ?? A. Permission modifiers
      ?? B. member variables and member methods can be decorated
      ?? C. Members whose modifications are only accessible in this class
    • Private application
      ?? (1) The member variable is modified with private;
      ?? (2) provide the corresponding getxxx () and Setxxx () methods. 3.this keywords

      Function: When our local variables and member variables are the same, if this is not used, the problem of the local variable hidden member variable is caused.
      Feature: The reference object of the current class;

      4. Construction method
    • Overview
      ?? Role: Create an object, initialize it to a member of the object
      ?? Features: A. The method name is the same as the class name;
      ???? B. No return value type, not even void
      ???? C. No specific return value
    • Overloading Considerations for construction methods
      ?? (1) If the construction method is not given, the system will automatically provide a non-parametric construction method;
      ?? (2) If the construction method is given, the system will no longer provide a default parameterless construction method (it is recommended to always give a non-parametric construction method).
    • Two ways to assign a value to a member variable
      ?? Setxxx () method
      ?? Construction method

Anonymous object, encapsulation (private), this keyword, construction method

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.