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

What are the two member accesses in the java class

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what are the two member visits in the java class". The explanation in the article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the two member visits in the java class"?

1. Static members

Static members belong to the class, and class access is required for access.

The static member open space is open when this type of memory is first loaded.

2. Non-static members

Non-static members belong to objects and need to be accessed by objects.

When an object is instantiated, non-static members open space.

In static methods, non-static members cannot access them directly.

Using a non-static method, static members can be accessed directly.

3. Examples

Class Person {String name; static int a; void eat () {} static void sleep () {}} class Program {public static void main (String [] args) {Person xiaoming = new Person (); / / access non-static member xiaoming.name = "xiaoming"; xiaoming.eat (); / / access static member Person.a = 10 Person.sleep () / Note: / / access static members, you can also use objects to access, but there will be warnings / / it is recommended to use classes to access static members}} Thank you for your reading. This is the content of "what are the two member visits in the java class?" after the study of this article I believe that you have a deeper understanding of what the two members of the java class visit are, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Development

Wechat

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

12
Report