Can you extend a static inner class in Java?

Java 8Object Oriented ProgrammingProgramming

A static inner class is a nested class which is a static member of the outer class. It can be accessed without instantiating the outer class, using other static members. Just like static members, a static nested class does not have access to the instance variables and methods of the outer class.

You can extend static inner class with another inner class.

Example

Live Demo

public class SampleClass {
   static abstract class Test{
      int num = 300;
      public abstract void display();
   }
   class DemoClass extends Test{
      public void display() {
         System.out.println("Hi how are you");
      }
   }
   public static void main(String args[]){
      SampleClass obj = new SampleClass();
      obj.new DemoClass().display();
   }
}

Output

Hi how are you
raja
Published on 08-Jan-2018 12:09:00
Advertisements