20165305 Suzhenrong "Java Programming" Fourth Week study summary

Source: Internet
Author: User

Fifth Chapter 5.1 Package

Encapsulation (encapsulation) actually uses methods to hide the data of a class, to control how much the user modifies and accesses the data, to hide the details of the object, and to manipulate the object as a black box. Encapsulating the initialization process by means of a constructor (constructor) encapsulates the data through member variables through a member method (function) encapsulation operation

5.2 Class Syntax details

1. If you do not declare a permission-decorated member, you can only access it directly in the class program code of the same package, that is, "package scope permissions." If you want to access the class or object members of a package in the class program code of another package, the class or object member must be a public member and declared in Java in the same state.
2. If you define a class without composing any constructors, the compiler automatically joins a parameterless, empty-content constructor called the default constructor. You can define multiple constructors, which are called overloaded constructors, as long as the parameter type or number is different.
3. In Java, this () represents the invocation of another constructor, and the This () call can only appear in the first row of the constructor.
4. A member declared as static is not owned by an individual object but belongs to a class.
5. In the case of class naming instances, the first letter is capitalized, in static usage, by the class name and "." operator to access.
6. The This keyword does not appear in the static method or block. Non-static data or method members cannot be used in a static method.
7. Use the import static syntax to be aware of name collisions, and some name conflict compilers can be parsed in the following order.
Local variable overrides: Select a variable with the same name, parameter, and method name in the method.
Member overrides: Select a data member, method name defined in the class with the same name.
Overloaded method Comparison: Using the various static members of import static, if there is a conflict with the same name, try to pass overload judgment.

The sixth chapter inherits:

Object-oriented, in order to avoid repeating defining common behavior among multiple classes. (simply, promote the same program code to the parent class.) )

Characteristics:

Here comes the new keyword, extends, which inherits the behavior of the parent class in the Java language using Estends.
Is-a principle, a subclass of Java can inherit only one parent class. To begin to understand polymorphism, you must first know what kind of action the object is.
Polymorphic, using a single interface to manipulate multiple types of objects.
After inheriting the parent class, you define the same method deployment as in the parent class, but the execution is different, called redefining.
If a method block really does not have any program code operations, you can directly use abstract to identify the method as an abstract method, the method does not have to write {} chunks, directly ";" to the end.

Attention:

The keyword extends is intended to augment and inherit the behavior of the parent class.
In Java, a subclass can inherit only one parent class.
When judging what kind of action the object is, check the logic of the syntax is correct, from the right to the left to read: The right is not a left side (the right class is not the subclass of the Left class)?
In the redefinition, the subclass must compose the same signature as the parent class method, and if the typos are completely different because of negligence (although the compilation succeeds but the behavior is completely different), labeling @override after JDK5 indicates that the compiler is required to check whether a method in the parent class is actually redefined.
Subclass if you inherit an abstract class, there are two approaches to abstract methods, one is to continue labeling the method as abstract (must be annotated before class), the other is to manipulate the abstract method, and if none is implemented, a compilation error occurs.

Inheritance and Law details: features:

Protected member permissions keywords, classes in the same package can be accessed directly, and classes in different packages can be accessed directly from the inherited subclass. (Access is not open, but can be accessed directly
If you want to get the method definition in the parent class, you can call the method before adding the Super keyword.
The final keyword definition is used before class, which means that the class is the last one, no more subclasses, and is no longer inherited. When defining a method, it can also be qualified to final, which means that the last method is defined, that is, the subclass can not redefine the final methods.
In Java inheritance must inherit the java.lang.Object, simply say any class traced back to the topmost class must be the Object parent class.

Attention:

There are 3 permissions keywords in Java, public, protected, and private, but there are actually 4 permission scopes.
If the original member is public, the subclass is redefined as private or protected.
Before JDk5, when redefining a method, the other part must be exactly the same as the method signature in the parent class, in addition to defining a keyword with a larger permission.
When creating an ArrayList instance, you can specify the initial capacity of the internal array, and if you use the parameterless constructor, the default capacity is 16.
Garbage collection: In the execution process, objects that cannot be referenced by variables are garbage objects identified by GC (garbage Collection).
Abstract class: Although it is an abstract method, it can still be called in the Go () method.
Code Hosting (CH5,CH6)

Script

20165305 Suzhenrong "Java Programming" Fourth Week study summary

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.