What is the difference between abstract class & Interface.

Showing Answers 1 - 16 of 16 Answers

arunapratap_k

  • Jul 18th, 2005
 

ABSTRACT CLASS contains general methods aswell as abstract methods whereas INTERFACE contains only abstract methods. 
A programmer uses Abstract class to specify the common features of all objects 
and abstract methods when the methods have diff. implementations for diff. objs. 
he himself writes the classes implementing abstact methods. 
A programmer writes an Interface when he doesn't know how to implement the features of a s/w and he leaves the implementation to be provided by 3rd party vendors

  Was this answer useful?  Yes

padmareddy

  • Aug 10th, 2005
 

what is clone interface 

  Was this answer useful?  Yes

M.Manikumar

  • Aug 13th, 2005
 

An abstract class contain both abstract and concrete methods where as an interface contains only abstract methods.

  Was this answer useful?  Yes

Sachin

  • Aug 28th, 2005
 

interfac is 100 % abstract class.All the methods in interface is implictly abstract.interface does not hava body.But in Abstract class there must be one method to be concrete itself

jeet

  • Sep 26th, 2005
 

interfaces are 100% abstract entities. they must have all methds having no body(abstract methods), while in abstract classes , its not necessary to have any abstract method. it can have or it might not have.

  Was this answer useful?  Yes

kranthi

  • Sep 26th, 2005
 

in interface all the methods should be declared as abstract

in abstact class all methods need not be declared as abstract and if we do not provide the implementations of all the methods of the abstract class the class that extends this class should be declared as abstract

  Was this answer useful?  Yes

Masthan

  • Sep 26th, 2005
 

    In interface all data members are final and static means they wont be  changed and can be called by using classname and "." operator and we can provide multiple inheritance which is  not possible in the case of abstract classes.abstract classes contains general methods as well as abstract methods.

  Was this answer useful?  Yes

sathish

  • Oct 2nd, 2005
 

RE: What is the difference between abstract class &am...

  Was this answer useful?  Yes

Aashish Renapurkar

  • Oct 8th, 2005
 

Choosing interfaces and abstract classes is not an either/or proposition. If you need to change your design, make it an interface. However, you may have abstract classes that provide some default behavior. Abstract classes are excellent candidates inside of application frameworks. Abstract classes let you define some behaviors; they force your subclasses to provide others. For example, if you have an application framework, an abstract class may provide default services such as event and message handling. Those services allow your application to plug in to your application framework. However, there is some application-specific functionality that only your application can perform. Such functionality might include startup and shutdown tasks, which are often application-dependent. So instead of trying to define that behavior itself, the abstract base class can declare abstract shutdown and startup methods. The base class knows that it needs those methods, but an abstract class lets your class admit that it doesn't know how to perform those actions; it only knows that it must initiate the actions. When it is time to start up, the abstract class can call the startup method. When the base class calls this method, Java calls the method defined by the child class. Many developers forget that a class that defines an abstract method can call that method as well. Abstract classes are an excellent way to create planned inheritance hierarchies. They're also a good choice for nonleaf classes in class hierarchies.

  Was this answer useful?  Yes

radhey

  • Apr 18th, 2006
 

abstract class has at least one method abstract and it has more than one method abstract and that method should be implemented by the class.

In case of Interface it should be all method abstract bydefault and it necessary to implemented.If programmer implements all the method of the class then he uses the interface and interface is a keyword in java.

  Was this answer useful?  Yes

krishna

  • Feb 20th, 2007
 


 Interface is a pure(100 %) abstract class. Then why abstract class seperatly?

It's the design criteria,For example we are writing one class that has methods implemented which are common to other classes .And some methods are different for different classes...Those methods left as abstract,Hence the class who needs the behaviour should implement the abstract methods.

Where as interface is like a template common for many objects...The interface provider just give the methods ,Some body has to implement all the methods....



  Was this answer useful?  Yes

aditya_8584

  • Mar 23rd, 2009
 

In Iterface we can have only prototype of method i.e all methods are abstract but in abstract class we can have abstract method as well as solid method also.

Second is in interface all variables are final and must be initialized but in abstract class that is not a case.

  Was this answer useful?  Yes

rajivsh101

  • May 20th, 2009
 

  1. Interface can have only static variable and abstract methods.
  2. Subclass has to implement interface using implement keyword.
  3. Always interface variable are public
  4. Always interface variable are final.
  5. Always interface variable are static.
  6. Always interface methods are public
  7. Interface  allow multiple inheritance.

  Was this answer useful?  Yes

rajivsh101

  • May 20th, 2009
 

Abstract class can have instance variable, static variable, constructor, abstract methods, concrete methods, instance blocks and static blocks.
Subclass has to extend abstract class using extend keyword.

  Was this answer useful?  Yes

Features of an Abstract Class
1. Abstract Class cannot be instantiated.
2. An Abstract Class must be inherited.
3. It may have Concrete Methods.
4. It may have Abstract Methods.
5. An Abstract Method of an Abstract Class must be overridden.
6. An Abstract Class can only contain Abstract Method.

Features of an Abstact Class.
1.Interfaces Provide for Multiple Inheritance

  • Capturing similarities between unrelated classes without artificially forcing a class relationship
  • Declaring methods that one or more classes are expected to implement
  • Revealing an object's programming interface without revealing its class. (Objects such as these are called anonymous objects and can be useful when shipping a package of classes to other developers.)

  Was this answer useful?  Yes

laxminarsaiah ragiri

  • Dec 27th, 2011
 

Clone interface is marker interface which doest contains abstract methods. I want to say an empty interface.

  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