- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Static Nested Classes in Java
A nested class in Java is of two types i.e. Static nested class and Inner class. A static nested class is a nested class that is declared as static. A nested nested class cannot access the data members and methods of the outer class.
A program that demonstrates a static nested class is given as follows:
Example
public class Class1 { static class Class2 { public void func() { System.out.println("This is a static nested class"); } } public static void main(String args[]) { Class1.Class2 obj = new Class1.Class2(); obj.func(); } }
Output
This is a static nested class
Now let us understand the above program.
The class Class1 is the outer class and the class Class2 is the static nested class. The method func() in Class2 prints "This is a static nested class". A code snippet which demonstrates this is as follows:
public class Class1 { static class Class2 { public void func() { System.out.println("This is a static nested class"); } } }
An object obj is declared in the method main() in Class1. Then func() is called. A code snippet which demonstrates this is as follows:
public static void main(String args[]) { Class1.Class2 obj = new Class1.Class2(); obj.func(); }
- Related Articles
- Nested Classes in Java
- What is the difference between static classes and non-static inner classes in Java?
- Nested Classes in C#
- Nested Classes in C++
- C# Nested Classes
- Static methods in JavaScript classes?
- What are nested classes in C#?
- What are the different types of nested classes are defined in Java?
- Abstract Classes in Java
- Nested interface in Java
- Static variables in Java
- Static class in Java
- static Keyword in Java
- Explain wrapper classes in Java?
- Static and non static blank final variables in Java

Advertisements