Object-oriented concepts, class-to-object relationships

Source: Internet
Author: User

Basic object-oriented concepts:
1. What is Object-oriented
1, object-oriented is a kind of programming idea
2, object-oriented is a thinking way of thinking problem
2, the establishment of object-oriented thinking mode
1, first whole, then local
2, first abstract, in concrete
3, what can do, and how to do
3. How to learn object-oriented
1. Mastering an object-oriented language grammar
2, familiar with object-oriented design principles
3, familiar with object-oriented design patterns

Overview of Facing objects:
1. Three characteristics of the object (recognized): encapsulation, inheritance, polymorphism. (It can be said that the four characteristics: encapsulation, inheritance, polymorphism, abstraction)
2. In the development of the first object, do not set up an object, the actual object is to find objects, establish objects and maintain the relationship between objects.

The relationship of a class to an object:

What is a class
1, class is: classification, category
2, through the classification, we can distinguish different kinds of things, in daily life, we often do this
3, therefore, a class is a set of things that have the same attributes (attributes) and behaviors (methods)

A class is a template for an object that is an individual instance of a class
1. The class is the description of things in real life------mapped to Java, the description is class defined classes (classes are abstract, conceptual, representing a class of things, such as human, cat)
2. Object is the entity that these things exist-------concrete object is the corresponding Java in the heap memory with the new entity (object is concrete actual representative of a specific thing)

How to define a class:
1. In fact, defining a class is describing things as defining properties and behaviors, and attributes and behaviors become members of the class (member variables and member functions)
2. The attribute corresponds to a variable in the class, and the behavior corresponds to the method in the class

The definition format of the class
In Java, you can use the following statement to define a class
Class Name {
property name;
Return value type method name () {}
}

Requirements: Describe the car (color, number of tires). Describing things is describing the properties and behavior of things.

1 classcar{2     //The attribute that defines a thing corresponds to a member variable in a class3String color= "Red";4     intNum=4;5     //The definition behavior corresponds to a member function (method) in a class6     voidrun () {7System.out.println (color+ "...." +num);8     }9 Ten      One     /* A Public static void Mian (string[] args) { - car c = new car ();//You can create this class object in this class so that the car class can run independently -     } the     */ - } -  -  +  Public classObjectdemo { -      Public Static voidMain (string[] args) { +Car c=NewCar ();//production cars generate an entity in heap memory with the new keyword, and C is the reference variable of the class type that points to the object of that class A  at         //Command object to do things object name. Object Member -C.color= "Blue"; - C.run (); -     } -}

Object-oriented concepts, class-to-object relationships

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.