What is the main difference between interface and anonymous inner class in Java?
-
This description has been edited by another user. interface Hello { void show(); } class Demo implements Hello { void show() { System.out.println("i am in method of Demo class"); this.call(); } Hello h= new Hello() { public void show() { System.out.println("i am in method of anonymous class"); } //}; void call() { System.out.println("i am in call"); h.show(); } }; class AnyDemo { public static void main(String[] args) { Demo d= new Demo(); d.show(); }
-
Answer:
Anonymous classes are that they enable you to declare and instantiate a class at the same time. They are like local classes except that they do not have a name. Use them if you need to use a local class only once. Interfaces are opposite to anonymous classes where declaration and instantiation are not done at same time. You can take a look at below link for further information about anonymous classes http://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html
Anvitha Tunikuntla at Quora Visit the source
Other answers
Nafis Md
Related Q & A:
- What is the main export of Kenya?Best solution by Yahoo! Answers
- What are the main features of a community web site?Best solution by cardinalgroup.ca
- What are the main differences between a Mobile and a PDA?Best solution by Yahoo! Answers
- What is the best camcorder to get for a college class?Best solution by Yahoo! Answers
- What is the main difference between human and animals??Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.