The declaration syntax of a class in Java is: use the class keyword to declare a class. The first letter of the class name is capitalized, and subsequent letters can be uppercase or lowercase. Member variables consist of data types and variable names. The first letter of the variable name is lowercase. Member methods consist of return type, method name and parameter list. The first letter of the method name is lowercase.
Declaration syntax for classes in Java
In Java, use the class
keyword To declare a class, the syntax format is as follows:
<code class="java">public class <ClassName> { // 成员变量 // 成员方法 }</code>
<ClassName>
: Class name must start with an uppercase letter, and subsequent letters can be uppercase or lowercase. Member variables
Member variables are fields that store data in the class. The syntax format is as follows:
<code class="java"><DataType> <VariableName>;</code>
<DataType>
: The type of data, such as int, double, String, etc. <VariableName>
: Variable name must start with a lowercase letter, and subsequent letters can be uppercase or lowercase. Member method
Member method is the behavior defined in the class. The syntax format is as follows:
<code class="java"><ReturnType> <MethodName>(<ParameterList>) { // 方法体 }</code>
<ReturnType>
: The return type of the method, if the method does not return any value, it will be void
. <MethodName>
: The method name must start with a lowercase letter, and subsequent letters can be uppercase or lowercase. <ParameterList>
: Method parameter list, if the method has no parameters, it will be empty. The above is the detailed content of What are the declaration syntaxes for classes in java. For more information, please follow other related articles on the PHP Chinese website!