[Summary] 2016.12.6 Tuesday

Source: Internet
Author: User

Advanced Concepts for classes
Access modifiers: Each member of a class (including member variables, methods, and constructors) has an access modifier to determine who can access
Four levels of access in Java, with permissions from large to small:
1. Open Access level: public
2. Protected Access level: protected
3. Default Access level: No access modifier (can be called the same package)
4. Level of private access: private

The encapsulation of the Get/set method embodies:
1. You can provide only get or set only. To change a property to read-only or write-only
2. Permission validation can be provided, and set can provide valid validation of the data.
3. Can hide the internal properties of the storage form

Static: Statics Property
When the property is not modified with static
1. Syntactically, this property must be accessed with an object
2. In memory, this attribute is placed on each object (each object has a Name property)
3. Semantically, this property belongs to an object
4. When a variable is created, it is the time of the new object
5. According to semantic analysis, few variables are properties that are static
6. Normal property, non-static property
When the property uses the static modifier
1. Syntactically, although the object can be accessed, but more is the class name directly access
2. In memory, this attribute is not placed on the object, but is stored in the data section of the static area, and the whole class share a value, change the whole.
3. Semantically, this property is related to the class and is Object-Independent
4. The time the variable is generated is when the class is loaded
5. Constant properties can be directly designed as public static final without consideration
6. Static properties, class properties

Static: Statically method
When there is no method to use the static modifier
1. Semantically, you must use objects to make calls
2. A non-static method can either manipulate static properties and manipulate non-static properties, either by invoking a static method or by invoking a non-static method
3. Loading on non-static method is loaded after
4. Semantically, if the method is related to an object, it can only be designed as a non-static
5. Design, if the implementation part of the method needs to manipulate the properties and other methods associated with the object, then the method is set to non-static
When the method of static modification is used
1. Syntactically, although the object can be used but more is called directly with the class name
2. Static methods can only manipulate static properties, call other properties, or even write This/super
3. On load static method first load
4. Semantically, a method is designed to be static if it is not related to the object, but only to the class.
5. In the design, if the method is a tool-class method of tools. Then the method should be designed as static

The generality of Static:
1. All static is not related to the object, are class-level,
2. All static will have special treatment during the loading period

Initialize block
Representation: {Initialization block}--The actual initialization block
1. The code block is automatically executed when the new object is constructed, and the new one executes once
2.new object construction method to perform 4 steps, the code block is executed before 3 steps, that is, before the property is initialized, so that the property in the initialization block first assignment, will be overridden by the third step assignment

static {Initialize} statically initialize block
1. The code block is automatically executed when the class of Personbean is loaded, only once, so the static initialization block is executed only once.
2. So many open resources, the pre-load action that opens the link can write to static initialization block
Inner class
In Java, you can also define classes within a class, a class that is defined inside a class, called an inner class, and the class in which the inner class is called an external class
A class file of a separate character
can also produce objects
also need to compile
Polymorphic
Polymorphic: Multi-state in OOP refers to the ability of an object to have multiple forms
A word describing polymorphism: the same behavior, different implementations
Classification
Static polymorphism: The effect of a method implementation at compile time (method overloading can be implemented)
Dynamic polymorphism: The implementation effect is not determined at compile time and is implemented with binding objects at runtime (using dynamic binding and overriding implementation)

Transformation of basic data:
1. Automatic type transformation, implicit conversion, small range data type conversion to a wide range of data types, risk-free, positive success
2. Coercion of type conversions, explicit conversions, conversion from a wide range of data types to a small range of data types, risk, loss of precision, meaningless
Conversions of reference data types:--only classes that have inheritance relationships can use type conversions
1. Upward type conversion, automatic type transformation, implicit conversion, small range data type conversion to a wide range of data types, risk-free, sure success, the parent application can point to the object of the child class
2. Down type conversion, forced type conversion, explicit conversion, from a large range of data types to a small range of data type conversion, there is a risk, syntax does not error, may throw an exception, terminate the program's operation
3. Only if it is running, does this class reference refer to this class of objects or to the parent class reference to the subclass object to succeed

[Summary] 2016.12.6 Tuesday

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.