Java Learning lesson Sixth (object oriented)

Source: Internet
Author: User

Object oriented first understand what is object-oriented?

Object-oriented: It is to deal with objects constantly.

Early Problem solving is a process-oriented approach (in simple terms, it is a step-by-step process, that is, the emphasis on action), such as C language, the use of functions, the function of the call.

Thought:

Object oriented: An object is emphasized, and an object refers to an entity. c++,java,c#

Example: Loading an elephant into a refrigerator

Process-oriented implementation: 1. Open the refrigerator 2. Store Elephant 3. Close the refrigerator

Object-oriented implementation: (Find entities, entities encapsulate these functions, that is, to find refrigerators, refrigerators with open, storage, shutdown function)
1. Refrigerator open 2. Refrigerator Storage 3. Refrigerator off

Object-oriented features:

1. Conform to people's thinking habits. 2. Simplifying Complex issues

3. The role shift is directed towards the object, which is the process-oriented performer and becomes the object-oriented leader.

(The point of the earth is that the object has the function that you need, how to do it, it's none of our business)


So solve a problem, first find out if there is no solution to this problem object, if not, write an object yourself.

An example of object-oriented thinking:

Interviewer recruiters, is a good example of object-oriented, enterprises accept a project, design, writing, testing, the interviewer can be completed, but a lot of waste of time and energy,
So he needs to recruit some people to help complete, and the object refers to the people who are recruited, they have the design, writing, testing and other functions, but specifically how to achieve, the interviewer does not
Need to know. What the interviewer needs to do is to find the object and direct him to solve the problem.

In Java, anything can be an object.
Objects are object-looking objects, objects are not object-created, and the relationships between objects are constantly maintained.

Object-oriented features:

1. Encapsulation 2. Inheritance 3. Polymorphism

Rule: Which object, when it is most clear about an action, defines the action in that object. Moving companies to move things, they just need to tell, where the porter can move, as to how to move, the Porter is the most clear, nature to carry this action is defined in the object of handling workers.

(Directing objects to do things)


Code Understanding:

/* Defining a class is a member of the definition class, which is the component * member function: the corresponding is the function of things * member variables: The corresponding is the property *  *///Concrete Embodiment */* Describe the handling process * Porter This position is composed of attributes and functions * properties: 1. Number of people 2. Gender * Function: Handling * * Class Man{int num;//member string sex;//member void function ()//member {SYSTEM.OUT.PRINTLN (num+ ".... "+sex);} /*public static void Main (string[] args) {//man This class simply describes something that runs only when it is used, does not require it to run independently, and of course it can//so, to use this thing, just in a class, Create and invoke its object to}*/}/* describe car * properties: quantity, Color * function, start */class car{int num = 3; String color = "Blue"; void Run () {System.out.println (num+ "... "+color);}} public class Main {public static void main (string[] args) {/* Complete the creation of the object and define the name of the object *///create a man entity, implement man BLF1 with the new keyword = new man ( );//define a man type variable Blf2,man is a class, BLF2 is a variable name//variable that is defined by a class, is a variable of class type, points to the object of the class Blf1.function ();//Use the contents of the object, form: Object. Member to complete calling car BLF2 = new Car (); Blf2.run ();//object. Component}}



Not finished ....

Java Learning lesson Sixth (object oriented)

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.