Infolinks In Text Ads

Oct 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{
        }
    }
    }

    Anonymous Class -
    Any class written inside the class with out any name called anonymous class. Means anonymous class have no name. This class also written in methods parameter.
    Syntax of anonymous class are
    new class-name ( [ argument-list ] ) { class-body }

    or
    new Interface-name ( ) { class-body }
   
    Example -

    public class Test{
   
        void addThis(Test test){ }

        //Anonymous Class first
        this.equals(new Object(){
            public void OkTested(){
               
            }
            });

        //Anonymous Class Second
        this.addThis(new Test(){
            public Integer those(int x){
                return new Integer(x);
            }
        });
    }
   

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...