Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the two member accesses in the java class

Shulou Source: shulou.com Published: 2022-05-31 17:49:15 09月21日 Update

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!

Tags: Members static objects learning openness content examples methods space memory that is ideas situations articles is more knowledge knowledge points articles follow Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Redmi macOS Shulou Information Shulou Technology