Notes | Programming now the previous chapters are recorded in the previous few days, and the following chapters are slowly being released. I try to finish this book this month, many notes are my own reading experience, may be some expression is not right. If so, please correct me.
Fifth Chapter
1. In the Java original file, you can have multiple classes, but only one public class, and the class name is the same as the file name.
2. When the Java interpreter is running, it first goes to the CLASSPATH environment variables, which have paths in them, and the Java interpreter will take these directories to the root directory to find the class file. However, 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 have a conflict, and you need to specify the location of the class. Classpath requires uppercase
3. The Public,private,protect three access control characters in Java should be placed in front of the definition of each member of the class. Whether this member is data or method, an access control character is followed by a member, unlike C + +. Default control permissions are used when no three access control characters are written in Java.
4. Default control permissions (Package permissions): Classes within the same package can be accessed. Public: Anyone can access this member. Private: It means that except for this class (which contains the class of this member), no one else is accessible. Protect: Methods of the base class are accessible, but other classes cannot access
5. There can be only one public class per file (compilation unit), but there are multiple accessibility classes, and if there are two or more public classes in a file, the compiler will make an error. The name of the public class needs to be the same as the file name, including the case of the letters. Otherwise the compiler will also make an error. The file can have no public class, although this is rare, then the file name can be arbitrarily taken.
6. Classes cannot be private and protect, classes have only two types, public and package types. If you don't want someone to access this class, you can set the constructor to private so that no one else can create the object of the class, and you could provide a static method to create the object. (Note one: Another effect is that the class constructor is private.) Then it cannot be inherited. Note Two: The inner class can make private and protected. (a bit confused, later chapters to understand))
7. Two main reasons for access control: one is to prevent users from touching things they shouldn't touch. This will simplify their understanding of the class. Second, the designer of class library can modify the internal operation mechanism of the class library without disturbing the client programmer.
Sixth Chapter
1. In the design of a basic principle. Design the data as private type. The method is designed to be a public type. Of course, the special situation can be adjusted.
2. A method of a base class (such as draw ()) may be modified in a derived class, and you can use Super.draw () when you still need to call the method of the base class ()
3. In the constructor of a derived class, the parameterless constructor of the base class is called automatically. If the base class does not have a default constructor (a constructor without parameters), you must explicitly call the constructor of the base class using the super and the appropriate parameters, and the statement must be placed at the very front of the derived class constructor, which executes the constructor of the base class and executes the constructor of the derived class.
4. Final has three uses, respectively for data, methods (method), and classes (class)
L final when used for data, when the data type is the original type, the data is a constant. When this data type is the object's reference, it shows that the reference is a constant, and once the reference is connected to an object, it cannot be connected to another object. But the object's own data can be modified (the static description is only one), and final data can be assigned at the time the data is declared, or it can be assigned in the constructor. We can use final in parameters, which means that reference cannot point to other objects while participating in the Operation
L Final Used method: There are two functions of final method, one is to lock the method, prevent derived class to modify, two reason is efficiency, if the method is final. The compiler then converts the call to inline (inline)) (the compiler automatically determines whether it is inline)
L final is used in class: it means that you no longer inherit this class, nor do you allow others to inherit it. Since this class can no longer be inherited, all the methods of the class are implicitly changed to final
5. Initialization of a class in inheritance: Initializes the static of the base class and then the static of the derived class. Then, when the object is created, all variables of the original type in the object become the initial value, all reference become null, and then the constructor of the base class is called, calling the constructor of the derived class
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.