Can you extend a static inner class in Java?


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

Updated on: 30-Jul-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements