See "Java Programming Thoughts" Notes (5-6)

xiaoxiao2021-03-06  102

Now, the previous chapter is recorded in the past few days. The following chapters should be released slowly. I strive this month after watching this book, a lot of notes are coming out of myself, maybe some expression is wrong. If so, Please correct it.

chapter Five

1. In the Java original file, you can have multiple classes, but you can only have a public class, and this class name and file name are the same.

2. When the Java interpreter is running, it first goes to the classpath environment variable, and there is a path in these variables, and the Java interpreter will find the Class file in the original directory. But if you use a JAR package, you need to add the file name to the middle of the environment variable. If you have the same class name, you can conflict, this time you need to clearly refer to the location of the class. ClassPath requires capitalization

3. The three access controls in Java, which should be placed in front of each member of the class. Regardless of this member is a data or method, an access control is only a member behind it, not like C . Use the default control permissions if you have not written three access control characters in Java.

4. Default Control Permissions (Package Permissions): The class in the same package can be accessed. Public: Anyone can access this member. PRIVATE: Indicates that other methods of this class (including class of this member), other people cannot access. Protect: The method of the base class can be accessed, but other classes cannot be accessed.

5. You can only have a PUBLIC class in each file (compilation unit), but you can have multiple auxiliary features at the same time. If there are two or more PUBLIC classes in a file, the compiler will report. The name of the PUBLIC class needs to be the same as the file name, including the same case of the letter. Otherwise the compiler will also report. There is no public class in the file. Although this is rare, the file name can be taken casually.

6. Category cannot be private and protect, and classes have only two types, public and package types. If you don't want others to access this class, you can set the constructor to Private, so others have no way to create this class object, you can provide a Static method to create an object. (Note One: Another impact is that this type of constructor is a private type. Then it cannot be inherited. Note 2: Internal classes can make private and protected. (A little do not understand, to be understood later))))

7. Two main reasons for access control: One is tobontan to touch what they should not touch. This simplifies their understanding of the class. Second, the designer of the class library can modify the internal running mechanism of the class library without alarming the customer programmer.

Chapter Six

1. One basic principle in design. Design data as a Private type. The method is designed as a public type. Of course, it can be adjusted in a special situation.

2. In the derived class, the base class may modify a method (such as DRAW ()), which can use super.draw () when the method of calling the base class is still required.

3. In the constructor of the derived class, the parameterless constructor of the base class is automatically invoked. If the base class does not have the default constructor (no parameter constructor), the SUPER and the appropriate parameters must be used to clarify the constructor corresponding to the base class, and the statement must be placed in front of the derived class constructor, the compiler will first Perform the constructor of the base class, perform the constructor of the derived class.

4. Final has three purposes, which are used for data (DATA), METHODs, and class L final, when the data type is the original type, indicating that this data is a constant. When this data type is an object's Reference, this Reference is a constant. Once the Reference is connected to an object, it is no longer connected to other objects. However, the data of this object can be modified (STITIC instructions only one), and the FINAL data can be assigned in the declaration data, or the value can be assigned in the constructor. We can use Final in the parameter, which cannot point to other objects when refrescence is involved in the operation.

l Final For the method: There are two functions for the method for the method, one is to lock the method, prohibiting the registration class from being modified, two reasons are efficiency, if the method is Final. Then the compiler is called to the inline (this compiler will automatically determine if inline)

l Final is used for class: It is equal to that you no longer inherit this class, you don't allow others to inherit this class. Since this class cannot be inherited, all methods of classes are implicit to Final

5. Initialization of the class in the inheritance: first initialize the Static of the base class, then the Static of the derived class. Then create an object, then all original type of variable in the object will become an initial value, all Reference becomes NULL, then call the constructor of the base class, the constructor of the derived class

转载请注明原文地址:https://www.9cbs.com/read-97202.html

New Post(0)