如何在 Java 中编写类名?
在编写类名时,你需要记住以下几点。
- 不应该使用预定义或现有类名作为当前类的名称。
- 不应使用任何 Java 关键字作为类名(大小写相同)。
- 类名的第一个字母应大写,其余字母应小写(小写字母)。
class Sample
- 同样,名称中每个词的第一个字母应大写,其余字母应小写。
class Test
- 建议保持接口名称简单且有描述性。
- 最好不要在编写类名时使用缩写。
示例
public class Test {
public void sample() {
System.out.println("This is sample method");
}
public void demo() {
System.out.println("This is demo method");
}
public static void main(String args[]) {
Test obj = new Test();
obj.sample();
obj.demo();
}
}
输出
This is sample method This is demo method
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP