- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is a static class in Java?
You cannot use the static keyword with a class unless it is an inner class. A static inner class is a nested class which is a static member of the outer class. It can be accessed without instantiating the outer class, using other static members. Just like static members, a static nested class does not have access to the instance variables and methods of the outer class.
Syntax
class MyOuter { static class Nested_Demo { } }
Instantiating a static nested class is a bit different from instantiating an inner class. The following program shows how to use a static nested class.
Example
public class Outer { Java Arrays with Answers static class Nested_Demo { public void my_method() { System.out.println("This is my nested class"); } } public static void main(String args[]) { Outer.Nested_Demo nested = new Outer.Nested_Demo(); nested.my_method(); } }
Output
If you compile and execute the above program, you will get the following result −
This is my nested class
- Related Articles
- What is a static class in C#?
- What are Class/Static methods in Java?
- Static class in Java
- What are static members of a Java class?
- What is a non-static class in C#?
- What is a static storage class in C language?
- Class and Static Variables in Java
- What are the steps to read static members in a Java class?
- How to access Static variable of Outer class from Static Inner class in java?
- Can you extend a static inner class in Java?
- How static class Object is created without reference of outer class in java?
- What are static methods in a Python class?
- What is static binding in Java?
- What is static import in Java?
- What are the differences between a static and a non-static class in C#?

Advertisements