“public static void”在Java中意味着什么? [英] What does 'public static void' mean in Java?

查看:294
本文介绍了“public static void”在Java中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java中的 public static void 是什么意思?

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.

这篇关于“public static void”在Java中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆