CAN WE MAKE A CLASS STATIC ?

Mayank Tripathi

Total Post:807

Points:4035
Posted by  Mayank Tripathi
Java  Class 
 631  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

    Points:4035
    Can we make a class static ?

    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();
     }
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!