Home > DeveloperSection > Interviews > Can you explain about Static class in Java ?

Posted on    July-04-2015 12:58 AM

 Java Java 
Ratings:
 1 Answer(s)
  344  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Points:4035
Posted on    July-04-2015 12:58 AM

A class can be made static provided that the class is a nested class. A nested class is class which is defined inside a class. But top class can't me made static. Example :
public class Test

 static class StaticInnerClass
 {
 public static void innerMethod()
 { System.out.println("Static Inner Class!"); }
 } 
 public static void main(String args[])
 {
 Test.StaticInnerClass.innerMethod();
 }
}

Don't want to miss updates? Please click the below button!

Follow MindStick