- 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 class in Java
In Java concept of static class is introduced under concept of inner classes,which are specially designed for some delicate functionality in a class.
Static class in Java are allowed only for inner classes which are defined under some other class,as static outer class is not allowed which means that we can't use static keyword with outer class.
Static class are defined same as other inner class in Java only with static keyword in front of its name.These class have some unique characteristics which made them differ from other non static inner class,these features of static class are as mentioned below −
Static class do not need to create an instance of outer containing class in order to create its own instance.
Static class can access members(variables/methods) of outer containing class only if they are static in nature.Which means that a static nested class does not have access to the instance variables and methods of the outer class.
Example
public class StaticInnerClass { static String str = "hi all"; static class Inner { private int a = 10; public void demoMethod() { System.out.println("Hi to all guys!"); System.out.println("Can access properties of outer class as : "+ str); } } public static void main(String[] args) { Inner inObj = new Inner(); inObj.demoMethod(); System.out.println(inObj.a); } }
Output
Hi to all guys! Can access properties of outer class as : hi all 10
- Related Articles
- Class and Static Variables in Java
- How to access Static variable of Outer class from Static Inner class in java?
- What is a static class in Java?
- Static import the Math Class Methods in Java
- What are Class/Static methods in Java?\n
- Can you extend a static inner class in Java?
- Why static methods of parent class gets hidden in child class in java?
- How static class Object is created without reference of outer class in java?
- What are static members of a Java class?
- Static class in C#
- Declare static variables and methods in an abstract class in Java
- How do I create static class data and static class methods in Python?
- How to instantiate a static inner class with reflection in Java?
- How to call a non-static method of an abstract class from a static method in java?
- The static storage class in C++
