Java BASICS (7) JavaSE and javase

Source: Internet
Author: User

Java BASICS (7) JavaSE and javase

Object-oriented

Process-oriented: process-oriented thinking emphasizes process (action ).

Object-oriented: Objects (entities) are emphasized in object-oriented thinking ).

Features:

1. Object-oriented is a common idea. Meets people's thinking habits.
2. The emergence of object-oriented architecture simplifies complicated problems.
3. The emergence of Object-oriented has changed the performer in the process to the conductor in the object.

 

Class and object:

The java language describes things in real life and is embodied in the form of classes.

The description of a thing usually focuses on two aspects: one is attribute and the other is behavior.

You only need to clarify the attributes and behaviors of the transaction and define it in the class.

Class: The description of a transaction.
Object: an instance of this type of transaction. Created in java through new.

A definition class is actually a member of a definition class.
Member: member variable <--> attribute, member function <--> action.

 

Differences between member variables and local variables:

1. member variables are defined in the class and can be accessed throughout the class.
Local variables are defined in functions, statements, and local code blocks and are only valid in the region.

2. member variables exist in heap memory objects.
Local variables exist in the stack memory method.

3. member variables exist with the creation of objects and disappear with the disappearance of objects.
Local variables exist with the execution of the region and are released with the completion of the region.

4. All member variables have default initialization values.
No Default initialization value for local variables.

Anonymous object

Anonymous object: an object without a name, such as new Car (); is a simplified format for defining objects.
Note the following when using an anonymous object:

1. When an object calls a method only once, it can be simplified to an anonymous object.

2. Anonymous objects can be passed as actual parameters. For example, show (new Car ());

Encapsulation

Encapsulation: hides the attributes and implementation details of an object and only provides public access.

Benefits:

Isolate changes.

Easy to use.

Improve reusability.

Improve security.

Encapsulation principles:

Hide all content that does not need to be provided externally.

Hide all attributes and provide public methods to access them.

 

Private: private. It is a permission modifier used for member variables and cannot be used for local variables.

Private content is only valid in this class.

Note: Private is only an embodiment of encapsulation.

Related Article

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.