How is a method in the same class as the main method not a static class called?
* Arraydemo class objects use object invocation function
Arraydemo ad=new Arraydemo ();
But since Arraydemo is a test class that typically creates other objects and invokes functionality in other classes with other class objects, you need to provide a tool class that specializes in manipulating arrays
If the constructor method of the tool class is modified by private, then the object cannot be created to invoke the method in this class, using the static modifier to call directly with the class name
Study on the problems of formal parameters and return values
* Form parameter:
* Basic data type, what data type is required, what data type is passed when the actual parameter is passed, and the change of form data has no effect on the actual parameters.
* If the actual parameter is a reference type, create an object for the class
* Concrete Class: Create objects of this class
* Abstract class: The subclass of the abstract class needs to be created (abstract polymorphism)
* Interface: Because the interface cannot be instantiated, the interface sub-implementation class needs to be defined and then instantiated through the child implementation class
* Return value:
* Specific class: Returns the Class object directly (usually using an anonymous object)
* Abstract class: A subclass object that needs to return a subclass of the class
* Interfaces: Sub-implementation class objects that require interfaces (can be implemented with anonymous objects)
Inner class
Defining another class in one class
Characteristics
* Internal classes can directly access members of external classes, including private
* External class to access members of the inner class must create an object of the inner class to access the class
In the test class, access the format method of the inner class member:
The external class name. Internal class Name Object name = External class object name. Inner Class object name
Classification
* member Inner class: position in external class member
Modifier for member Inner class: Prinvate (Guarantees data security), static
for a static member inner class, whether a member method in a static member inner class is static or non-static, to access the member variable of an external class, the variable must be modified by static
* Local Inner class: Defines the local variable position in the outer class
either local member inner class or member inner class (non-static) can directly access external class members including private
Questions:
* Local internal class access to local variables why is there a problem?
* Current local variable error, must be final modified why?
This is because the local variable is generated with the invocation of the method, disappears with the call of the method, and now has a local inner class at the local location, which is to be accessed at its own member method location, the variable must be changed to a constant (which needs to be final decorated: custom constants) and the value of such variables is always fixed.
Anonymous inner class:
is a simplified version of the inner class
Prerequisite: A class must exist (can be a concrete class, or it can be an abstract class)
Write format: New interface or class name () {
Method overrides;
}
When an anonymous inner class has only one method, it can be directly new[] () {}. Method name ()
When an anonymous inner class has two or more than two methods:
Internal class name Object name =new internal class name ();
Essence: Inherits the class or implements a subclass object of the interface
Java Learning Lesson 09