Java Object-oriented review

Source: Internet
Author: User

Object: The only thing that really exists.

Class: The common property of the same type of thing and the extraction of public behavior.


Java object-oriented language:

Core idea: Find the right object to do the right thing.


How to find an object:

Way one: Sun has defined a lot of classes, and we just need to know these classes to create object usage.
Way two: We need a custom class to create an object from a custom class.

Use code to validate or overturn a concept that you have questions about while you're organizing your notes.

Custom class Three steps:
1. Customize a class.
class {
Public properties of things use member variable descriptions


The public behavior of a thing uses a function description.
}
2. You can create an object from a class.
3. Access (set) the properties of the object or methods that call the object.


the difference between a member variable and a local variable:
1. Custom Location Differences:
1. A member variable is a variable within a class that is defined outside the method.
2. A local variable is a variable declared within a method.
2. Difference in function:
1. The role of a member variable describes the properties of a class of things.
2. The function of a local variable is to provide a variable for internal use within the method.
3. The difference in life cycle;
1. The member variable exists as the object is created and disappears as the object disappears.
2. A local variable is called when the corresponding method executes to the statement that created the variable, and once out of its scope disappears from memory immediately.
4. Differences in initial values:
1. The member variable has the default initial value.
2. A local variable has no default initial value and must be initialized before it can be used.


Anonymous object: The object to which no reference type variable refers is called an anonymous object.

Details of the anonymous object to note:
1. The properties of anonymous objects are generally not assigned, because they are never available.
2. Two anonymous objects can never be the same object.

Anonymous object benefits: Simplify writing.


Application Scenarios for anonymous objects:
1. If you call an object's method one time, and then the object is no longer in use, you can use an anonymous object at this time.
2. You can call a function as an argument.

Packaging:


Steps for encapsulation:
1. Use the private adornment property that needs to be encapsulated.
2. Provide the Get or set method settings and get properties as needed.

Benefits of Encapsulation:
1. Improve the security of the data.
2. Simple operation.
3. The implementation is hidden.

Note: The properties of the general entity class are encapsulated.

Java Object-oriented review

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.