Posts

Showing posts from October 22, 2010

Outer Inner and Anonymous Classes java

Outer and Inner Class in Java

    In Java, Class which is written inside the class called Inner Class. Class which has the inner class called outer class.
    There are four types of Inner Class in java.

1)Static nested class
2)Member Class
3)Local Class
4)Anonymous Class


Static nester class -
    Any class written inside the class with static keyword called  Static nester class.

    Example -
    public class Test{

        /* Static nested class*/
        static class InnerClass{

        }
    }

    There is  InnerClass is  Static Nested Class.

Member Class -
    Any class written inside the class without the static keyword called member class.

    Example -
    public class Test{

        /* Member class*/
        class InnerClass{

        }
    }

Local Class -
    Any class written inside the method of outer class called Local inner class.

    Example -
    public class Test{
        void addThis(Test test){
        /* Local class */
        class InnerClassC{
        }
    }
   …

about Heap and Stack Memory in Java

Stack  Memory Allocation and Heap Memory Allocation

In Java Virtual Machine, There are two type of memory allocation process.
1)Stack  Memory Allocation
2)Heap Memory Allocation

Stack  Memory Allocation -
           When ever any class will be written in java, this files content will goes in the  Stack  Memory Allocation area.

Example:-

           class TestA{
        int x=10;
        int y=20

        public int add(int x, int y){
        return x+y;   
        }
    }

    The class A will be stored in Stack  Memory Allocation area.

Heap Memory Allocation -
    When ever object of any class will be made then this object will be stored in Heap Memory Allocation area.

Example :-
            If  we are making the object of the above class

new TestA();

    then this object will stored in Heap Memory Allocation area.

Please Notice it -
Deep Understanding about this example -

    If you are making object of this class and assign this object into variable.
     TestA  testa = new  TestA();

   …

Recent Post

Recent Posts Widget