GeekInterview.com
Series: Subject: Topic:
Question: 990 of 995

What is the difference between abstract class & Interface.

Asked by: Interview Candidate | Asked on: Aug 28th, 2005
Showing Answers 1 - 16 of 16 Answers
arunapratap_k

Answered On : 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

  
Login to rate this answer.
padmareddy

Answered On : Aug 10th, 2005

what is clone interface 

  
Login to rate this answer.
M.Manikumar

Answered On : Aug 13th, 2005

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

  
Login to rate this answer.
Sachin

Answered On : 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

Yes  1 User has rated as useful.
  
Login to rate this answer.
jeet

Answered On : 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.

  
Login to rate this answer.
kranthi

Answered On : 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

  
Login to rate this answer.
Masthan

Answered On : 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.

  
Login to rate this answer.
sathish

Answered On : Oct 2nd, 2005

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

  
Login to rate this answer.
Aashish Renapurkar

Answered On : 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.

  
Login to rate this answer.
radhey

Answered On : Apr 18th, 2006

View all answers by radhey

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.

  
Login to rate this answer.
krishna

Answered On : 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....



  
Login to rate this answer.
aditya_8584

Answered On : Mar 23rd, 2009

View all answers by aditya_8584

In Iterface we can have only prototype of method i.e allmethods are abstractbut 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.

  
Login to rate this answer.
rajivsh101

Answered On : May 20th, 2009

View all answers by rajivsh101

  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.

  
Login to rate this answer.
rajivsh101

Answered On : May 20th, 2009

View all answers by rajivsh101

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.

  
Login to rate this answer.

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.)

  
Login to rate this answer.
laxminarsaiah ragiri

Answered On : Dec 27th, 2011

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

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.