What is the difference between interface and abstract class

Showing Answers 1 - 14 of 14 Answers

reena sahoo

  • Sep 1st, 2005
 

INTERFACE 
1.all methods are abstract. 
2. does not use abstract keyword before abstract method. 
 
ABSTRACT 
1. ATLEAST ONE METHOD IS ABSTRACT. 
2. uses the abstract keyword before abstract method.

  Was this answer useful?  Yes

riteshyadav14@rediffmail.com

  • Sep 8th, 2005
 

An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.

PavanKumar

  • Jun 16th, 2006
 

hello,

The Main Difference Between the Abstract Class And the Interface are:

1)When inheriting A Interface We have to inherit all the methods of the Interface there's no other option whereas with abstract classes we can inherit the members that we are in need of.

2) The Main difference between these is that Interface cannot have any declaration within it. Just the interface has to have body of the method and the method is to be used by the classes inheriting it. Whereas in the case of Abstract Class it can have declarations (Other than the abstract method) and it can be further extended in the classes inheriting the Abstract Class.

 

 

  Was this answer useful?  Yes

Amar

  • Aug 16th, 2006
 

Abstract Class: A class that cannot be instantiated.  An abstract class is a class that must be inherited and have the methods overridden.  An abstract class is essentially a blueprint for a class without any implementation.

Interface: Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes

 



  Was this answer useful?  Yes

Prasant

  • Sep 1st, 2006
 

An abstract class can have all concrete methods.check it.

  Was this answer useful?  Yes

YCS REDDY

  • Mar 2nd, 2007
 

Abstract Class:
(1)it contains both abstract methods and non abstract methods
(2) object can't be created just through reference we are calling all the methods
(3) it is implemented by subclass , i.e which class is extended from this,
abstract class contains only nonabstract, this situation also code will compile fine, but problem at runtime
abstract can't be declared with  Final, Synchronized, Native, just your requirements you implement some methods in the abstract class
this class also contain Constructor

========
Interface contains all abstract methods,
all methods compulsory implemented by particular class
interface does not contain Constructor,

anooshay

  • May 16th, 2008
 

Interface: In interface just signature of the methods are defined(means abstract meathod). there is no a single method which has body.
e.g. void add();

Abstract class: In a abstract class some method are abstract while some are concrete methods. we use abstract keyword when we declare a abstract method.
abstract keyword also used to declare class.
we cannot creat object of abstract class.
we cannot create constructor of abstract class.
e.g.
abstract class A
{
    abstract void add();
     void subtract()
     {
          int a,b;
           a=10, b=5;
           int c=a-b;
           System.out.println(c);
       }
}

ashokhullur

  • Jul 22nd, 2010
 

Abstract classes can have only non abstract methods. Its not mandatory that it must have atleaset one abstract method.

Declaring class using keyword abstract is enough to make class as abstract.

  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