what is the difference between abstract class and
Interface?where we can use it in realtime projects?

Answer Posted / vinod

We use Abstract class and interface to enforce some rules to the classes which extends/implements. For example we can define a class say "Bird" and we can declare methods say "Fly()", "Walk()". This means whatever the class that is derived from Bird has to override or give definition for Fly() and Walk() and therefore we are making sure that all the derived classes follows or has the common functionalities. In other way the classes derived from superclass should have common properties. In addition to this the derive class can have its own methods like "Swim()"...

In case of Abstract class we can define COMMON functionalities in super class and those can be used in the derived class where as in Interface we cant do that. ( this i would say as advantage of abstract class)

In case of Interface the derived class can implement any number of interface but restricted to extend only one abstract class (this i would say as advantage of Interface)

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is meant by the value of a variable?

462


Can we access instance variables within static methods ?

573


What are different access specifiers in java?

571


How does varargs work in java?

615


What is parsing in java?

536






If I only change the return type, does the method become overloaded?

541


What is difference between static class and normal class?

535


Should you use singleton pattern?

528


What is empty string literal in java?

567


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

624


What are jee technologies?

538


How to create a custom exception?

576


What is an association?

553


Explain the difference between arraylist and linkedlist in java?

486


Justify your answer that you can't define a method inside another method in java, if you can then how?

606