INNER CLASS: ============ ==> A CLASS WITHIN ANOTHER CLASS IS CALLED AS "INNER CLASS" Ex: MobilePhone{ SimCard{ } } ==> inner class is dependent class of outer class. Syntax: class OuterClass{ class IneerClass{ } } ==> The Data members of outer class can extend to inner class. Whereas the data members of inner class cannot extend to outer class. ==> The outer class always be allowed to define with either public type or default type only. Whereas the inner class can allow define with any access modifier (default/public/private/protected). How to create the object for the inner class: ============================================= ==> two ways: 1) within method of outer class package AIT.IO.Java; class OuterClass{ int x; private int y; public class InnerClass{ int p; private int q; public void m11() { System.out.println("x = "+x); System.out.println("y = "+y); } } OuterClass(int x,int y) { this.x = x; this.y = y; } public void m1() { InnerClass ic = new InnerClass(); ic.p = 100; ic.q = 200; System.out.println("p = "+ic.p); System.out.println("q = "+ic.q); ic.m11(); } } public class MainClass { public static void main(String[] args) { OuterClass oc = new OuterClass(1000,2000); oc.m1(); } } 2) In outside of the outer class ================================== Syntax: outer-class-name.inner-class-name Identifier_inner_class_object = outer-class-object.new inner-class-name(); ex: OuterClass o = new OuterClass(); OuterClass.InnerClass obj = o.new InnerClass(); package AIT.IO.Java; class OuterClass{ int x; private int y; public class InnerClass{ int p; private int q; public void m11() { System.out.println("x = "+x); System.out.println("y = "+y); } } OuterClass(int x,int y) { this.x = x; this.y = y; } } public class MainClass { public static void main(String[] args) { OuterClass oc = new OuterClass(1000,2000); // creating the object for the inner class OuterClass.InnerClass oi = oc.new InnerClass(); oi.m11(); } } ======================================== ==> Inner class can be defined with "static". ==> the Non-static data member of outer class can't access in the inner class if the inner class is static type. ==> To create the object of static inner class in outside the outer class: Syntax: outer-class.inner-class object-reference = new Outer-class-name.Inner-class(); package AIT.IO.Java; class Outer{ private int x; private static int y; static class Inner{ private int x = 20; private static int p; Inner(int p) { this.p = p; } public void m11() { System.out.println("Static Varaiable = "+Outer.y); } } Outer(int x,int y) { this.x = x; this.y = y; } // public void m1() // { // Inner iobj = new Inner(1122); // iobj.m11(); // } } public class Main { public static void main(String[] args) { Outer oobj = new Outer(112,121); //object for the inner class Outer.Inner aobj = new Outer.Inner(123); aobj.m11(); // oobj.m1(); } }