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

Does java support Operator Overloading?

615


What is the difference between a choice and a list?

612


What are recursive functions?

581


What is the largest number a double can hold?

571


What is flush buffer?

525






Where are the card layouts used?

618


What is bufferedwriter?

547


Is a class subclass of itself?

616


What are access specifiers available in java?

588


How many bytes is double?

553


How do you sort a string in java?

545


Explain the JDB in depth & command line.

578


what is mutual exclusion? How can you take care of mutual exclusion using java threads? : Java thread

691


Is java good for beginners?

587


Explain when we should make an instance variable private.

624