• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Difference between Abstract Class and Interface, Which scenarios we are using both?  RSS feed

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Difference between Abstract Class and Interface, Which scenarios we are using both?

Any one can , Please reply with examples.

Thanks
Koti
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abstract class can also have non-abstract methods in it. but, interfaces can't have non-abstract methods.

Abstract class can have constructors where as interfaces can't have constructors

Abstract class can be extended to only one sub class....(Single inheritance) where as you can implement multiple interfaces

bot abstract classes and interfaces can't be instantiated.

Regards,
Anu





 
Bartender
Posts: 4097
63
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Koti Samadhi wrote:Difference between Abstract Class and Interface, Which scenarios we are using both?


Hi Koti,
Both expose the concept "Abstraction". Abstract classes are useful when you need to provide a common set of method implementation(s) for all the subclasses to share. Most modern frameworks build around the concept of interfaces.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Purpose of both abstract class and interface is almost the same, except you can use abstract class when some of the implementation is fixed(few methods are implemented) and rest of the implemtation is left to the user.
 
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Santhosh Reddy wrote: . . . and rest of the implemtation is left to the user.

Probably better to say "and the rest of the implementation will be different in the subclasses."
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi this is simple....
In Interface only abstract and public access specifiers are allowed...
In abstract classes all normal access specifiers are allowed..
abstract classes should not be instantiated..
Use abstract keyword for abstract classes..
Use interface keyword for interfaces..

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

s.palanivel rajan wrote:hi this is simple....
abstract classes should not be instantiated..
[/color]



Do you mean that if you want you can but you should not ?

s.palanivel rajan wrote:



cool yaar. from where you have picked up these habits ?
 
s.palanivel rajan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


why ??dont you saw the left side of message window
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please avoid pretty coloured text; many people find it difficult to read. I have changed the previous text to black.
 
s.palanivel rajan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok cambell.. no problem i understand...
but if it is the case then why these colours are given...
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nice replies.it was helpful for me
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. A few colours might be helpful, but . . .
 
You get good luck from rubbing the belly of a tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!