Dark Horse Programmer--java Basic---object-oriented understanding

Source: Internet
Author: User

------<a href= "http://www.itheima.com" target= "blank" >java training, Android training, iOS training,. NET training </a>, look forward to communicating with you! -------

Object-oriented understanding

One: Understanding Object-oriented

1, what is an object

      object is the real life thing, can say all things are objects. such as: tables, chairs, computers, televisions and so on.

3 main features of an object:

A) object behavior: What this object can do to make this object do what it does. Such as: Bicycles can be used to ride.

b) The state of the object: When the object's method is manipulated, the object remains in a particular state. Such as: Can Twist bicycle turn.

c) The identifier of the object: You can distinguish between objects with the same behavior or similar state by using identifiers, which can differentiate between objects. such as: the color of bicycles.

2, Object-oriented concepts

A) object-oriented is relative to process-oriented

B) Object-oriented and process-oriented are a kind of thought, the early thought is the process-oriented, through the continuous evolution to

The object-oriented

c) Process-oriented

The emphasis is on functional behavior

D) Object-oriented

Encapsulates functionality into objects, emphasizing functional objects

E) Object-oriented is a process-oriented

   f) Object-oriented, refers to writing a program around the function of an object to write.

Example: Elephants put in refrigerators

1 Opening the refrigerator

2 elephants put in the fridge

3 Close the refrigerator

Note: We focus on the process, focusing on the behavior involved in the process, that is, the function (open function, storage function, Shutdown function).

So what did we do to turn him into an object? That means we're not looking at the process now, but on the object.

so the idea turned, since these are the behavior of refrigerators, we just have to operate the refrigerator in the function we can, we put these actions all

are defined in the refrigerator, the refrigerator is a real object, which we call the object.

So what we see is no longer open, stored, closed.

What we see is actually a thing refrigerator.

Two: Object-oriented features

Object-oriented Four features: encapsulation, inheritance, polymorphism, abstraction.

Encapsulation: Refers to the description of a thing is unique to this thing, can not let the outside world to see some member variables and methods.

In Java, member variables and methods are encapsulated in classes, and they need to be accessed through a few unique methods.

Inheritance: is a pattern that occurs between classes and classes, and is a subclass of a class that shares the parent class member variables and methods. By extending the subclasses ' methods, you can make subclasses more powerful than the parent class.

Polymorphism: Refers to the two states of the object at run time and compile time, and the use of polymorphism makes the code more flexible and reusable.

Abstract: Refers to certain behaviors and actions of this class when defining a class. Such as: Bicycles can be moved.

But how to move is not explained. This is an abstract class that defines some actions and behaviors in advance.

Three: Classes and objects

Class: A way of describing things in the Java language, described as classes defined by class.

Object: The entity in which this kind of thing actually exists, in Java with new , the entity in heap memory.

Why is an object in memory or an entity?

We found that the object contains a lot of data, we use entities to store the data, like arrays, arrays can store some data, objects can also store data,

All we call entities for storing multiple data. are placed in heap memory.

Four: Member variables and local variables

Scope of Action:

Member variables: Acting on the entire class

Local variable: Acting in a function, or in a statement

In-memory location:

Member variable: In heap memory, it exists in memory because the object exists.

Local variable: exists in the stack memory.

When participating in an operation:

Member Variable: There is a default initialization value because he is in heap memory.

Local variables: Uninitialized is not possible to participate in the operation, because he is in the stack memory,

You must have an initialization value to participate in the operation.

Five: Anonymous objects

1, an anonymous object is a simplified form of an object

Such as:

1  New Car (); 2   C. num = 5; 3 4   // into: 5 New Car (). num = 5;

2, anonymous objects two usage cases

A) when only one call is made to the object method

b) Anonymous objects can be passed as actual parameters

-----------Android Training, Java training, Java Learning Technology blog, look forward to communicating with you! ------------

Dark Horse Programmer--java Basic---object-oriented understanding

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.