Home > DeveloperSection > Interviews > Can we make a class static ?

Posted on    July-06-2015 12:30 AM

 Java Java  Class 
Ratings:
 1 Answer(s)
  436  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Points:4035
Posted on    July-06-2015 12:30 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