What is practical difference between abstract class and interface? What is practical implementation of polymorphism?

Questions by rajthebest

Showing Answers 1 - 12 of 12 Answers

sambit

  • Apr 14th, 2007
 

abstract class: partially implemented.
    use:used when u know some of the implementations.Ex-dataset
           Here u know that tables can be stored but what dimensions......?
           but u know tables have rows n columns and can be implemented.

interface: these are fully abstract.U can't imlement anything here.
     Use:used for assigning methods 2 be implemented.
             At the top level u can't decide(or make design decision) on the implementaion always & is taken care by the classes that implement them.

  Was this answer useful?  Yes

s.jabee

  • Jun 7th, 2007
 

Abstract class :
1. Atleast one abstract method has to be present (method without implementation).
2. Generally are base classes (*)
3. Can contain Virtual methods (Methods has implementation in the Base class but still to be overridden in the derived class for polymorphism ).

Interface:
1. Forms a set of rules which the implementing class has to abide to.
2. Can appear in any level of the class hierarchy unlike Abstract Class which will be always Base class. (*)
3. Cannot contain other access modifiers for the methods apart from public which is by default.

  Was this answer useful?  Yes

shankan25

  • Jun 4th, 2008
 

Interfaces
=======
   
we can use interfaces when somebody to start from scratch to implement the method from interface or their orginal purpose was different from exits interface then they can use interface.

Also a class can implement more interfaces(multiple inheritance)

Interface all variable are public,static and final and all methos by default public and abstract methods.

we cann't implement method in the interface, instead based on the purpose the class imlpementing the interface have to implement the method for their own purposes.

just importing the package of interface will allow anyone to use interface, so it's easy.

performance wise it's slow because there is extra redirection.

Abstract Class;
===========

abstract class has morestructured and it has default implementation in it.

we can extend abstract clas but cann't instantiate.

Because it has default implementation third party usage is should be use this abstract class as a base class. it cause restructuring their own class and class can inherit from only one base class.

method we declaring abstract should have abstract key word and abstract method should be declared inside abstract class.

calss extending abstract class should be implementing abstract methods unless the subclass is abstract class.

it's more fast than interface.

it can contain not static and final variable and contain static methods.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions