GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  Programming  >  Java
Go To First  |  Previous Question  |  Next Question 
 Java  |  Question 66 of 928    Print  
What is the difference between interface and abstract class

  
Total Answers and Comments: 7 Last Update: May 16, 2008   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: anooshay
 
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);
       }
}

Above answer was rated as good by the following members:
kottalam, russp
September 01, 2005 15:08:51   #1  
reena sahoo        

RE: What is the difference between interface and abstract class
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.

 
Is this answer useful? Yes | No
September 08, 2005 16:30:19   #2  
riteshyadav14@rediffmail.com        

RE: What is the difference between interface and abstract class
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.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
June 16, 2006 05:51:51   #3  
PavanKumar        

RE: What is the difference between interface and abst...

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.


 
Is this answer useful? Yes | No
August 16, 2006 05:43:53   #4  
Amar        

RE: What is the difference between interface and abst...

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




 
Is this answer useful? Yes | No
September 01, 2006 04:41:57   #5  
Prasant        

RE: What is the difference between interface and abst...
An abstract class can have all concrete methods.check it.
 
Is this answer useful? Yes | No
March 02, 2007 08:00:31   #6  
YCS REDDY        

RE: What is the difference between interface and abst...
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

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
May 16, 2008 00:48:38   #7  
anooshay Member Since: May 2008   Contribution: 1    

RE: What is the difference between interface and abstract class
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);
}
}

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape