Learn about the knowledge of classes and objects in Java

Source: Internet
Author: User
Tags abstract definition

In the Classes and Objects section, we know that in an object-oriented programming language, a class is a separate program unit, a collection of objects with the same properties and methods, and in a Java program, the general format of a custom class is:

Class name

{

Data members 1

Data members 2

Data members 3

......

Member Method 1

Member Method 2

}

The description section of the class consists of the keyword class and the class name, noting that the name of the class follows the definition rules of the Java identifier. The class body is the entire content of the curly braces in the class declaration, which is made up of member variables (attributes) and member methods (methods).

Said class, then is the object of the cut-out, the object is to map the fact of the objective world to object-oriented program design, the problem domain of things abstracted into objects, the static characteristics of things (attributes) it is a set of data to describe, the dynamic characteristics of Things (behavior) is represented by a set of methods. To create an object, you declare the object and build the object, declaring the object in the following format:

Class name Object Name table, (object name table refers to one or more object names, if multiple object names, separated by commas.) ,)

The format of the object is: Class Name Object Name =new constructor method ();(The role of the keyword new is to establish an object and allocate storage space for the object. )

Because an object can have many properties and multiple methods.

In an object-oriented system, the properties and methods of an object are tightly integrated into a whole, and the two are indivisible, and qualifying an object's property value can only be read and modified by this object or its methods.

When an object is created, the object has its own data members and member methods, and we can use the object by referencing the members of the object.

The data members of the object are referenced in the following way:

The name of the object. data member name;

The object's member methods are referenced in the following way:

The name of the object. Member method name (parameter list);

Finally, the relationship between the class and the object (the difference) is that the ⑴ class gives an abstract definition of all the objects that belong to the class, and the object is an entity that conforms to that definition. (2) The relationship between the class and the object can be regarded as abstract and concrete. ⑶ in object-oriented programming, an object is called an instance of a class, and a class is a template for an object. Here you know that because an object is an instance of a class, you should define the class before you define the object. After a class is defined, you can create an object on the basis of the class. In the process of learning, there is also the idea of deep cognition, there is no comprehensive understanding, just one-sided, in the back of time to deepen. Constantly improve the awareness of the point of expertise. to refuel!

Learn about the knowledge of classes and objects in Java

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.