Private members of the class can be accessed in the member functions of this class. Private members of a class are hidden in the derived class and can only be accessed from member functions of the base class.
Private members in Java are modified using private. (Recommended learning: Java Video Tutorial)
Private members can only be called in this class and cannot be seen outside this class. If you want to obtain private member variables in other classes, you can write a public get method in this class, and other classes can obtain private member variables by calling this get method.
class PrivateTest{ private String str = "私有成员变量"; //如果加上这个方法 public String getStr(){ return str; } public static void main(String[] args){ System.out.println(str);//这里可以调用到str变量 } } class OtherClass{ public static void main(String[] args){ PrivateTest pt = new PrivateTest(); //String tryToGet = pt.str;//这句编译会报错,str不可见 String getStr = pt.getStr();//这样 就可以获取到str的 } }
For more Java-related technical articles, please visit the Java Development Tutorial column to learn!
The above is the detailed content of Where are the private members of a class accessible?. For more information, please follow other related articles on the PHP Chinese website!

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.