What is the use of anonymous inner classes ?

Answer Posted / ashokkumar

Anonymous classes

1.These are one type of inner class that having no mame.

2.The syntax will come like

class a
{
public void mymethod ();

}
class b
{
a obja = new a(){//the anonymous class starts here
public void mymethod (){ //have to implement the methods of
//class 'a'
return "here we are implementing mymethod of class 'a'"
}

}; //when finishing anonymous classes we have to put";"

}

3.Here the anonymous class is consider as a sub class of
class 'a'.We can access all the variables and methods of
super class 'a' through the anonymous block,except local
variables,including private variables.

4.Through anonymous classes we can create instance for
Interfaces.

Is This Answer Correct ?    19 Yes 16 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Where import statement is used in a java program?

586


Difference between error and exception

4961


What does split function do in java?

505


What is the difference between processes and threads?

511


What is jit compiler ?

550






What is oop in java?

499


What is memory leak and how does java handle it?

498


What is the use of StringTokenizer class?

583


What is thread pool in java with example?

520


What is an accessor?

1005


What is a numeric digit?

560


What is a concrete classes? Is Java object class is concrete class?

485


When do you get classcastexception?

530


What is boolean keyword in java?

571


What are the different types of inner classes?

511