What is difference between abstract class and interface in Java
Abstract class and Interface are one of fundamental yet tricky topic in Object oriented design and analysis, and it's not easy to master. Few tips particularly on Java programming language to help you to make decision.Difference between abstract class and interface in Java
1) Interface in Java can only contains declaration. You can not declare any concrete methods inside interface. On the other hand abstract class may contain both abstract and concrete methods, which makes abstract class an ideal place to provide common or default functionality. I suggest reading my post 10 things to know about interface in Java to know more about interfaces, particularly in Java programming language.
Read more: http://krishnasinghprogramming.blogspot.com/2014/12/java-questions-and-answers.html
2) Java interface can extend multiple interface also Java class can implement multiple interfaces, Which means interface can provide more Polymorphism support than abstract class . By extending abstract class, a class can only participate in one Type hierarchy but by using interface it can be part of multiple type hierarchies. E.g. a class can be Runnable and Displayable at same time. One example I can remember of this is writing GUIapplication in J2ME, where class extends Canvas and implements CommandListener to provide both graphic and event-handling functionality..
Read more: http://krishnasinghprogramming.blogspot.com/2014/12/java-questions-and-answers.html
3) In order to implement interface in Java, until your class is abstract, you need to provide implementation of all methods, which is very painful. On the other hand abstract class may help you in this case by providing default implementation. Because of this reason, I prefer to have minimum methods in interface, starting from just one, I don't like idea of marker interface, once annotation is introduced in Java 5. If you look JDK or any framework like Spring, which I does to understand OOPS and design patter better, you will find that most of interface contains only one or two methods e.g. Runnable, Callable, ActionListener etc.
Read more: http://krishnasinghprogramming.blogspot.nl/p/inter.html
What is method overloading and overriding in Java?
In this Java tutorial we will see how Java allows you to create two methods of same name by using method overloading and method overriding. We will also touch base on how methods are bonded or called by Compiler and Java Virtual Machine and finally we will answer of popular interview questions difference between method overloading and method overriding in Java. This article is in my series of Java article which discusses about Interview e.g. Difference between Synchronized Collection and Concurrent Collection or How to Stop Thread in Java. Please let me know if you have some other interview questions and you are looking answer or reason for that and here in Javarevisited we will try to find and discuss those interview questions.
Read more: http://krishnasinghprogramming.blogspot.nl/p/inter.html
No comments:
Post a Comment
Please Comment Your Valuable Feedback....