Help the world stop coronavirus! Stay home!

Prev Next

Java / Class Variables (Static Variables)

What is a static class in Java?

A Class can be made static only if it is a nested class (class within a class). The nested static class can be accessed without having an object of outer class.

It can access static data members of outer class including private. Static nested class cannot access non-static data member or method.

If you have the static member inside static nested class, it can be accessed directly and you don't have to create instance of static nested class.

The static class are also known as static nested class or static inner class .

class OuterClassEx{  
  static int val=30;  
  static class InnerClassEx{  
   void msg(){System.out.println("Value is "+val);}  
  public static void main(String args[]){  
  OuterClassEx.InnerClassEx obj=new OuterClassEx.InnerClassEx();  

❤Cash Back At Stores you Love !!!❤

Earn your $10 reward when you make your first purchase through Ebates by signing up with clicking below button.

Ebates Coupons and Cash Back

More Related questions...

Show more question and Answers...

Instance Variables (Non Static Variables)

Comments & Discussions