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:  When to use Interface over abstract class?

Answer: Abstract Classes: Classes which cannot be instantiated. This means one
cannot make a object of this class or in other way cannot create
object by saying  ClassAbs abs = new ClassAbs(); where ClassAbs is
abstract class.

Abstarct classes contains have one or more abstarct methods, ie method
body only no implementation.

Interfaces: These are same as abstract classes only difference is we
an only define method defination and no implementation.

When to use wot depends on various reasons. One being design choice.

One reason for using abstarct classes is we can code common
functionality and force our developer to use it. I can have a complete
class but I can still mark the class as abstract.
Developing by interface helps in object based communication.



June 06, 2008 15:33:27 #9
 Karuna Reddy J2EE Expert  Member Since: June 2007    Total Comments: 38 

RE: When to use Interface over abstract class?
 
Interface:
1. If u want to implement all of the methods than we go for interface.
2. In future to put any methods that dows not effect.
3. To implemnting Inheritence Future

Abstarct:

1. when it necessay dont create the instance of the class for the security purpose.
     

 

Back To Question