Java中的“public static void"是什么意思? [英] What does 'public static void' mean in Java?
问题描述
public static void
在 Java 中是什么意思?
What does public static void
mean in Java?
我正在学习中.在本书的所有示例中,我从 public static void
开始工作,它出现在任何正在使用或创建的方法之前.这是什么意思?
I'm in the process of learning. In all the examples in the book I'm working from public static void
comes before any method that is being used or created. What does this mean?
推荐答案
这是三个完全不同的东西:
It's three completely different things:
public
表示该方法是可见的,可以被其他类型的其他对象调用.其他替代方案是 private
、protected
、package
和 package-private
.请参阅此处了解更多详情.
public
means that the method is visible and can be called from other objects of other types. Other alternatives are private
, protected
, package
and package-private
. See here for more details.
static
表示方法与类相关联,而不是与该类的特定实例(对象)相关联.这意味着您可以在不创建类的对象的情况下调用静态方法.
static
means that the method is associated with the class, not a specific instance (object) of that class. This means that you can call a static method without creating an object of the class.
void
表示该方法没有返回值.如果该方法返回 int
,您将编写 int
而不是 void
.
void
means that the method has no return value. If the method returned an int
you would write int
instead of void
.
这三者的组合最常见于大多数教程将包含的 main
方法.
The combination of all three of these is most commonly seen on the main
method which most tutorials will include.
这篇关于Java中的“public static void"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!