Classes are the basic elements that make up a Java program. A Java application is composed of several classes. Classes are the most important "data types" in the Java language, and variables declared by classes are called objects.
The definition of a class consists of two parts: class declaration and class body. The basic format is as follows:
class class name {content of class body}
class is a keyword used to define a class. "class class name" is the declaration part of the class, and the class name must be a legal Java identifier. The two braces {} and the content between them are the class body.
For example:
classFactory{floata[];Workmanzhang;}
"Class Factory" is called a class declaration, "Factory" is the class name, and "{float a[];Workman zhang;}" is the class body.
The purpose of a class is to abstract the common attributes and behaviors of a class of things, and to use a certain grammatical format to describe the abstracted attributes and behaviors. The key to abstraction is to capture two aspects of a thing: properties and behavior. Therefore, the content of the class body consists of two parts:
1) Declaration of variables: used to reflect the properties of the object.
2) Definition of methods: Methods can operate on variables declared in the class and reflect the behavior of the object.