- 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
How to access Static variable of Outer class from Static Inner class in java?
A class with in another class is known as inner class, you cannot declare a class static unless it is an inner class. A static inner class is just like other class variables. You can access it (static inner class) without instantiation
Example
You can access the static variable of an outer class just using the class name. Following Java example demonstrates how to access static variables of a class from a static inner class.
public class Outer { static int data = 200; static class InnerDemo { public void my_method() { System.out.println("This is my nested class"); System.out.println(Outer.data); } } public static void main(String args[]) { Outer.InnerDemo nested = new Outer.InnerDemo(); nested.my_method(); } }
Output
This is my nested class 200
- Related Articles
- How static class Object is created without reference of outer class in java?
- How to instantiate a static inner class with reflection in Java?
- Can you extend a static inner class in Java?
- How to access the object of a class without using the class name from a static context in java?
- Static class in Java
- How to call a non-static method of an abstract class from a static method in java?
- Class and Static Variables in Java
- How do I create static class data and static class methods in Python?
- Static class in C#
- What is a static class in Java?
- Java static variable
- What are static members of a Java class?
- Why static methods of parent class gets hidden in child class in java?
- Static import the Math Class Methods in Java
- What are Class/Static methods in Java?\n

Advertisements