This is a discussion on Difference between Interface and Abstract Class within the Java forums, part of the Programming Talk category; What is exact difference between Interface And Abstract Class ? Where exactly these Interface are useful in realtime scenario....
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
an abstract class is just a outline of the entire class. u can have only method name inside it. u can't create objects for them. a abstract class should always be inherited. where as a inteface is a collection or a group of empty methods.
Last edited by karthigayini; 10-29-2007 at 05:47 AM. |
|
|||
|
An abstract class is a class which may or maynot consist of the abstract methods while an interface must have all the functions as abstract.
the abstract class with all the functions as abstract must be defined as an interface. |
|
|||
|
Abstract class vs interface
Abstract class can (or not ) have methods in it and it has no use in instantiating it since it has no meaning in instantiation.
It has to be inherited for use . You need to INHERIT to use an abstract class. You can have a variable in Abstract class. ( a silly difference Basically u use an abstract class when you want to provide a generalized form of abstraction and leave the implementation task with the inheriting subclass. Interface - group of related methods with empty bodies . You need to IMPLEMENT to use an interface. I dont think you can have a variable in a interface. When you want a few classes to use a few methods which you dont want to be included in the class ,then you go for the interface, which makes it easy to just implement and make use of the methods defined in the interface. But the problem with the interface is that, u have to implement all the methods defined in the interface , even if you dont need some of them. |
|
|||
|
An abstract class is a class which may or maynot consist of the abstract methods while an interface must have all the functions as abstract.
the abstract class with all the functions as abstract must be defined as an interface. |
![]() |
| Thread Tools | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Common Interface to I/O | fernandez.dan@gmail.com | Software Patterns | 2 | 08-27-2005 10:19 PM |
| comp.lang.c Answers to Frequently Asked Questions (FAQ List) | Steve Summit | Tech FAQ | 0 | 06-01-2004 07:00 AM |
| comp.lang.eiffel Frequently Asked Questions (FAQ) | Franck Arnaud | Tech FAQ | 0 | 04-17-2004 08:27 AM |
| Smalltalk FAQ (v.1.0) | Vikas Malik | Tech FAQ | 0 | 04-17-2004 08:27 AM |
| Factory design pattern Vs abstract factory design pattern | Nimmi Srivastav | Software Patterns | 4 | 10-26-2003 11:06 AM |