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