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

What do you understand by a Static Variable?

616


What is the purpose of an interface?

544


What is the use of object and class classes?

555


Is it possible to compare various strings with the help of == operator? What are the risks involved?

603


What are different types of control structures?

475






Explain serialization and deserialization in java?

540


what state does a thread enter when it terminates its processing? : Java thread

588


Can we sort array in java?

515


How to sort array in descending order in java?

501


What is numeric data type?

514


What is factor r?

510


How are multiple inheritances done in Java?

608


What is the use of a conditional inclusion statement in Java ?

574


What is high level language in computer?

524


Explain about collection interface in java?

534