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  >  Interview Questions  >  J2EE  >  Java

 Print  |  
Question:  What is the difference between Abstract class and Interface

Answer:
Answered by Scott on 2005-05-12 10:03:06: An abstract class can contain non-abstract methods which do not have to be overridden in the subclass. 
 
There is no difference between a fully abstract class (all methods declared as abstract and all fields are public static final) and an interface.


January 01, 2008 13:48:06 #20
 Mithun Challa   Member Since: January 2008    Total Comments: 6 

RE: What is the difference between Abstract class and Interface
 
Ok this is one of the common interview questions. Let me put this in simple words

when you use Interface :
There can be different classes which  show different behaviour. Like consider a case I want to put all animals in a tree structure. I have top most defination as Animal then we have birds, reptiles, mammals etc.. Now all these have different features from each other yet they show some common features like they move they eat food ... so i will use Animal as interface and define those features in the class that implements it.

when you use abstract class:
when i want to show a is-a type of realtion. now lets go further with the same example now I want to further classify my birds as those which can fly and those that cann't fly.. now this is specific to the birds in here i will go with abstract class.


     

 

Back To Question