Thursday, January 16, 2025
HomeProgramming"What is a ""static class"" in Java? "

“What is a “”static class”” in Java? [closed]”

A static class in Java is a nested (inner) class that is declared with the static modifier. It belongs to its enclosing class and can be accessed without creating an instance of the outer class. A static class cannot access non-static members of its outer class directly, as it does not depend on an instance of the enclosing class.

See also  How to Check for NaN Values in Python

Example:

class OuterClass {
static class StaticClass {
void display() {
System.out.println(“This is a static class.”);
}
}
}

// Usage
OuterClass.StaticClass obj = new OuterClass.StaticClass();
obj.display();

Static classes are typically used for utility or helper classes and better organization.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x