• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Which one to choose abstract class vs interface while designing java code

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All
In which cases abstract classes are best choice then interface and vice versa.Real time example explanation is highly appreciated.
Thanks
Praveen
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I feel when Implementing calss has nothing in common go for Interface and when your Implementing calss has something in common go for abstract class.

Regards
Kanchan
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Skeletal implementation of an Interface

Hope this may help you
 
Marshal
Posts: 79401
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

seetharaman venkatasamy wrote:Skeletal implementation of an Interface

Hope this may help you

Afraid not. The link didn't open.

For abstract classes: you need to check there is an IS-A relationship. You can only extend one class. An abstract class can include implemented methods. For those implemented methods, it is preferable (preferable doesn't mean compulsory) for all your subclasses to use the same implementations.
For interfaces: all the interface methods must be empty. You can implement several interfaces as long as there is no inconsistency or collision between methods with the same signatures.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some links:

Interface vs. abstract class
Interfaces Vs Abstract Classes In Java
Abstract classes vs. interfaces - When does it make sense to choose an abstract class over an interface?

And from our own FAQ: Interface Vs Abstract Class
 
Campbell Ritchie
Marshal
Posts: 79401
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I wrote:[Afraid not. The link didn't open.

It's opening now. Peculiar
 
Create symphonies in seed and soil. For this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic