private OnClickListener clickFunction = new OnClickListener(){stmt; }
<p>I was trying a sample application on android. I could able to get the output.</p>

<h2>studentFormsActiviyt.java</h2>

<pre><code>package com.example.android.accelerometerplay;

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;
import android.content.Context;

public class StudentFormsActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // To specify the actions of the Buttons
        Button accept = (Button) findViewById(R.id.myButton1);
        Button reject = (Button) findViewById(R.id.myButton2);

        accept.setOnClickListener(clickFunction);
        reject.setOnClickListener(clickFunction);
    }

    private OnClickListener clickFunction = new OnClickListener(){
        public void onClick(View v){
            Context context = getApplicationContext();
            CharSequence text;

            switch(v.getId()){
               case R.id.myButton1: text="accept was pushed"; 
                                    break;
               case R.id.myButton2: text="reject was pushed"; 
                                    break;
               default: text="We didn't know what was pressed :(";  
            }

            int duration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(context,text,duration);
            toast.show();

        }
    }
 }
</code></pre>

<h2>main.xml</h2>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    &gt;
&lt;TextView 
    android:id="@+id/myLabel"
    android:text="Name of the student:" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    /&gt;
&lt;EditText
    android:id="@+id/myText"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_below="@id/myLabel" 
    /&gt;
&lt;Button
    android:id="@+id/myButton1"
    android:text="Accept:" 
    android:textColor="#00FF00"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_below="@id/myText"
    android:layout_alignParentRight="true"
    /&gt;
&lt;Button
    android:id="@+id/myButton2"
    android:text="Reject:" 
    android:textColor="#FF0000"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/myButton1"
    android:layout_alignTop="@id/myButton1"
    /&gt;
&lt;/RelativeLayout&gt;
</code></pre>

<p>But I could not understand this definition of the class "private OnClickListener clickFunction = new OnClickListener(){stmt; }". we used to declare the class as private class classname{stmt}; and then used to create the instance of the class. But in the above first declaration they are creating instance of the class and then they are defining.
why are they doing like this. Please help me to understand.</p>
