Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The function of java--public_private_void_static

Shulou Source: shulou.com Published: 2022-06-03 06:13:37 09月30日 Update

For beginners, these names are familiar but not fully understood.

The following explains one by one:

public and private (these two are for permission scope)

public xxx (){} is a public method that can be called by any class.

private xxx (){} is a private method, that is, it can only be called in this class and cannot be called by any other class.

void function returns a value type (functions can return multiple types of values, such as int, String, Float, etc.)

For example, publicvoid xxx (){} returns nothing after execution of this function.

But this function can be called by any other class because public is used.

Note: If a function returns nothing, but you name it without void, eclipse automatically indicates an error.

static

static is a static function, using static means that this function belongs to the class, and there is no need to create an object when calling it.

public static void test (){}

Instead of creating an object reference with new when called in the main method, you can simply type test () to reference the function.

QQ group: 610845268

Tags: Functions methods objects types no two that is beginners names multiple useful permissions scope errors problems static prompts explanations inputs functions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Tech Info Shulou Information Shulou Technology MariaDB