Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The function of java--public_private_void_static

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report