"Java from getting started to giving up" Javase Primer: Object-oriented Concepts (introductory version)

Source: Internet
Author: User

To know what is object-oriented, you must first have an object, so ... No object can go home to wash and sleep ·

Well, the front is a joke, to explain what is object-oriented, we still first

Example:

Xiao-hang: "Silly, what did you have for breakfast today?" ”

Little fool: "Eat more things, there are two pieces of bread, a chicken cake, a few leaves, a little salad sauce, and also drank a cup of coke, a bag of fried potatoes"

Small stay: "Little silly, you four not four sprinkle Ah!" Did you just say you ate chicken burger set?

Little fool: "Uh, okay, I'm having this chicken burger set."

OK, from the example above you can see what is object-oriented, the beginner can understand that: a lot of separate data and methods packaged together, it becomes an object.

In the following we will explain some of the concepts of object-oriented: classes, objects, properties, methods, encapsulation, inheritance, polymorphism, and through these concepts to understand what is object-oriented.

So, how many objects are there in this example?

First: Chicken Burger Package: Contains the properties of Chicken burger, French fries, cola

Second: Chicken Burger: Contains the properties of bread, chicken pie, lettuce, and sea-pull sauce

The third: a bag of fries: Contains properties there are many root fries, a packing bag

Fourth: A cup of Coke: A cup, some ice cubes, coke

Fifth one: ...

Is it found that this analysis can be endless??? Haha, that's right, this is object-oriented programming analysis.

Of course, in the actual development we will not continue to decompose, there is no need to end an object into atoms.

In general, we will analyze the specific objects according to the function , if some objects have the same properties and methods, we will attribute them to one class. How to analyze is what we are going to do next.

Introduction to Basic concepts

First, class:

A class is an abstraction of a set of objects with the same properties and methods, which is simply a concept, such as "Goddess" is a class

Goddess

Second, the object:

An object is an instance of a class, simply said to be a real object, is a concrete thing, such as some crossing goddess is very specific

Sister Lin Cang Jing sister

Jia elder sister

Third, attributes:

A property is a characteristic of an object, a noun, such as the goddess above having height, weight, name, age, and measurements, etc. ·

Sister Lam: 173cm,54kg, Lin Chi-ling, 43 and secrecy.

Cang Jing elder sister: 155cm,45kg, Cang Jing Empty, 34 and secrecy.

Jia elder sister: 166cm, Secrecy, Jialing, 35 and secrecy.

Iv. methods:

A method is an object's behavior, a verb or noun.

Sister Lin has the methods of swimming, running and making advertisements.

Cang sister has a photo shoot, film and other methods.

Jia elder sister has to play the sketch, sings and so on method.

Five, Package:

Encapsulation is good to understand, have sent and received parcels, this is a package

The biggest benefit of encapsulation is to hide the details, just reserve the user's attention to the function API is OK.

such as air conditioning, from the user's point of view, we are only concerned about the use of the following functions: Open, close, heating, refrigeration, temperature adjustment. How these functions are implemented, the corresponding electronic circuit diagram is what, the use of what kind of circuit board, etc., we do not care about or care.

Vi. Inheritance:

Inheritance should be understood, that is, dragon born Dragon, chicken born chicken, mouse son will make holes, if the situation below, you should ask the next door to the old king.

Seven, polymorphic:

Polymorphism in object-oriented means that different objects have different execution effects on the same instruction. For example, if you let the different gourd doll perform the "Enlarge Recruit ()" This method, the corresponding effect is different.

Let's introduce the basic concepts today, and next time we'll look at the Java syntax for these concepts.

"Software Thinking" blog address:51CTO, Blog Park , interested in small partners can go to see the relevant other blog posts.

"Java from getting started to giving up" Javase Primer: Object-oriented Concepts (introductory version)

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.