InnerClass in Java

package com.innertest;

 * @author taher_JAVAHUNTER
public class OuterClass {

    public class Inner {
        public void sayGood() {
    Inner inner = new Inner() {
        public void sayGood() {
            System.out.println("Good day");
        public void inMeth(){// This Method can't be called

    public void show(int i) {
        class MethLocClass{
            public void ty(){
                // i=10; Local variable can't be used
                //inner = null; Instance variable will be available

    public static void main(String[] args) {
        OuterClass oc = new OuterClass();
        OuterClass.Inner inner = new OuterClass().new Inner();
        OuterClass.StatClass statClass  = new OuterClass.StatClass();

    public static class StatClass{ // It is a nested class not an InnerClass
        int k=10;
        public void statMeth(){
                System.out.println("In statMeth : "+k);
Output :

Good day
In statMeth : 10

This entry was posted in Core JAVA, Just 4 Knowledge, SCJP. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s