GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Certification  >  Sun
Go To First  |  Previous Question  |  Next Question 
 Sun  |  Question 14 of 38    Print  
What is difference between abstract class and interface

  
Total Answers and Comments: 19 Last Update: July 22, 2008     Asked by: apt_dpl 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Praveen Kumar V
 
An Abstract Class can contain default Implementation, where as an Interface should not contain any implementation at all. An Interface should contain only definitions but no implementation. where as an abstract class can contain abstract and non-abstract methods. When a class inherits from an abstract, the derived class must implement all the abstract methods declared in the base class. an abstract class can inherit from another non-abstract class.

Above answer was rated as good by the following members:
basyonic
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
February 16, 2006 18:13:17   #1  
sandeepcheema007 Member Since: December 2005   Contribution: 8    

RE: what is difference between abstract class and inte...
There is no difference in the functionality of these two.The only difference is that a class cannot extend an abstract class if it already is extending some other class.An interface on the other hand can be implemented in any situation which makes them very powerful.Also user defined exceptions can be defined within an interface itself, which is not the case with an abstract class.
 
Is this answer useful? Yes | No
March 03, 2006 07:32:51   #2  
Praveen Kumar V        

RE: what is difference between abstract class and inte...
An Abstract Class can contain default Implementation, where as an Interface should not contain any implementation at all. An Interface should contain only definitions but no implementation. where as an abstract class can contain abstract and non-abstract methods. When a class inherits from an abstract, the derived class must implement all the abstract methods declared in the base class. an abstract class can inherit from another non-abstract class.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 05, 2006 01:01:52   #3  
kotesh Member Since: February 2006   Contribution: 2    

RE: what is difference between abstract class and inte...
1. Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. Inteface is a Java Object containing method declaration and doesn't contain implementation. The classes which have implementing the Interfaces must provide the method defination for all the methods.2. Abstract class is a Class prefix wtih a abstract keyword followed by Class definaton. Interacace is a Interface which starts with interface keyword.3. Abstract class contatins one or more abstract methods. where as Interface contains all abstract methods and final declarations.4. Abstract class contains the method defination of the some methods. but Interface contains only method declaration, no defination provided.5. Abstract classes are useful in a situation that Some general methods should be implemented and specialization behaviour should be implemented by child classes. Interafaces are useful in a situation that all properties should be implemented we can use this scenario
 
Is this answer useful? Yes | No
March 05, 2006 23:29:43   #4  
n.shah Member Since: March 2006   Contribution: 1    

RE: what is difference between abstract class and inte...

diff 1 )  interface must always have by default public and abstract methods

while abstract class can have non abstract methods

diff 2 ) all the variables in interface are by default public static final while ion abstract class you may have instant variables


 
Is this answer useful? Yes | No
March 27, 2006 15:17:43   #5  
achantakrishna Member Since: March 2006   Contribution: 2    

RE: what is difference between abstract class and inte...

the main differences between an interface class and abstract class are

1.abstract classes must be given by keyword abstract,where as in interface class with key word interface

2.every method in interface class should be abstract,but this is not necessary in abstract class

3.by default what ever variables we decalre in interface are public static final,where as in abstract class they can be default and instance variables also


 
Is this answer useful? Yes | No
April 04, 2006 01:40:32   #6  
shankar        

RE: what is difference between abstract class and inte...
Abstract Class is a class which must have at least one abstract method.Interface is a class which is having all abstract methods. By default interface methods are public abstract.
 
Is this answer useful? Yes | No
April 24, 2006 05:32:03   #7  
vara Rama Krishna Chadaram        

what is difference between abstract class and inte...

      Interface                             Abstract Class

---------------------------------------------------------------------------

(1)    Decelear with keyword                  (1)  Decelear with keyword  

         interface                                                Abstract.

(2)    It will not                               (2) Itwill may or may            contain      Constructor.                                     Constructor.

(3)  By default all methods                   (3) It may contact Abstract

   are Public AbstractMethods.                  methods and non

                                                          Abstract methods.

(4) it will contain only                          (4) It will final variables and

     final variables,                                    Instances Variables.


 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
October 22, 2006 13:11:11   #8  
chandrahasa reddy        

RE: what is difference between abstract class and inte...

Dear Greekintreview.com,

 everyday i searched this website regarding java information.i got sufficient information diff between interfaces and classes given answer for Mr Koteswara Reddy.

thanks for koteswara reddy


 
Is this answer useful? Yes | No
October 27, 2006 04:39:18   #9  
Dharmendra        

RE: what is difference between abstract class and inte...

Abstract Class means Blueprint of the model.

Interface means functionality of the model(Blueprint) if the class implements one(an interface).

Using Abstract class we can take n number of instances. Like using the Blueprint of a Car
we can take n number of similar cars. But we cannot use the Bluprint or model to drive the
car.That is the meaning of abstract. So, Car is the Blueprint and Ford Car is the derived class from car which uses all the
properties of class and some more properties which is specific to Ford.

Frog is a derived class from Mammal.

When it lives on land it implements the function of hopping.

when it lives on water it implements the function of swimming.

So we find that frog uses both methods hopping and swimming. So it is better to declare
in some interface so that any frog which implements the interface will define its own
way of transportation.

So let me create an Interface called Amphibian and give two method Swimming() and hopping().
It looks like

public interface Amphibian{

public void swim();
public void hop();
}

Let we define the Frog class as

public class Frog implements Amphibian{

public void swim(){

//Define your words
}

public void hop(){

//Define your words
}

}

The above class Frog when implements the interface Amphibian it has to define the methods
declared in the interface Amphibian. It can be an empty method. But it should be defined.

The use of an interface is any class which wants to use some remote functionalities can
implement that particular interface and can perform the task like man using Parachute to
fly in air.

- Compiled by Dharmendra


 
Is this answer useful? Yes | No
October 30, 2006 03:09:47   #10  
perireddy        

RE: what is difference between abstract class and inte...
abstract class contains both final and instance variablea .afinalvariable is also ainstance variable then what is the difference mr.koteswara reddy
 
Is this answer useful? Yes | No
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape