Algorithm (4th edition) -1.2.3 implementation of abstract data types

Source: Internet
Author: User

Summary: This section details the implementation of abstract data types, including instance variables, constructors, creation of instance methods, scope of three variables and APIs, use cases and implementations.

Focus:

1. If the instance variable should not be changed after initialization, we will use final.

2. If no constructor is defined, the class implicitly defines a constructor that does not accept any arguments by default and initializes all instance variables to their default values.

3. There is a key difference between instance methods and static methods: instance methods can access and manipulate instance variables.

4. Scope of three variables:

· Parametric variables: the whole method;

· Local variable: All statements after its definition in the current code snippet;

· Instance variable: the entire class.

5. If the instance variable has two semantics, you can use the this prefix to differentiate the instance variable.

 Public classExample {Private intvar; ...    Private voidmethod1 () {intvar//Local Variables. .. var//a local variable is called, not an instance variable... This. var//Invoking instance Variables    }    Private voidmethod2 () {... var//Invoking instance Variables    }    ...}

6. The role of the API is to separate the use and implementation.

Algorithm (4th edition) -1.2.3 implementation of abstract data types

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.