Home  |   STIU  |   WOW  |   SCJP  |   SCDJWS   |   JEE FAQ  |   About US  |  

FAQ
  Java FAQ
  JSP FAQ
  Servlet FAQ
 

Advertisement

XyzWs Java FAQ:
How to inherit from an inner class?


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend


Previous Next vertical dots separating previous/next from contents/index/pdf Contents
Advertisement
How to inherit from an inner class?

How to inherit from an inner class?


If the inherited inner class is a non-static inner class. This means that it can only be instatiated within the context of an instance of the enclosing class.

class Outer {
    class Inner { 
        void method() { 
            System.out.println("method called"); 
        }
    }
}

public class Program  extends Outer.Inner {
    Program() {
        new Outer().super();
    }

    public static void main(String[] args)  { 
        Program p = new Program();
        p.method();
    }
}

If the inherited inner class is a static inner class (Nested class).

class Outer {
    static class Inner { 
        void method() { 
            System.out.println("method called"); 
        }
    }
}

public class Program  extends Outer.Inner {
    Program() {
    }

    public static void main(String[] args)  { 
        Program p = new Program();
        p.method();
    }
}

 


Previous Next vertical dots separating previous/next from contents/index/pdf Contents

Support  | Feedback  | Help