This week's book giveaway is in the JDBC and Relational Databases forum.
We're giving away four copies of Murach's MySQL and have Joel Murach on-line!
See this thread for details.
Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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

interface and abstract class

 
Ranch Hand
Posts: 594
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interface and abstract class contains method signature,then what are the difference between both,I knew interface are useful for multiple inheritance.Where interface .abstract class would be used ?
 
Marshal
Posts: 79013
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please do a search of the Ranch; this has come up several times on this forum and beginners' in the last two weeks. You might find the old threads answer your question.
 
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
Also have a look at our FAQ: Interface vs abstract class
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by jacob deiter:
Interface and abstract class contains method signature,then what are the difference between both,I knew interface are useful for multiple inheritance.Where interface .abstract class would be used ?



Differences between both interfaces and abstract classes are

1. Interfaces are used for multiple inheritance while as per Java we can not extend more than one class.

2. Interfaces are only specifies variables and method signatures where Abstract classes can have variables and also methods with only signatures (Abstract Methods) and also methods with the implementation.

Similarities between these 2 is these both can not be instantiated.
 
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also whilst interfaces are 100% abstract, Abstract classes can have non-abstract methods, including a constructor one could say that there is a degree of abstraction flexibility between an abstract class and a interface.
 
Campbell Ritchie
Marshal
Posts: 79013
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would go farther than that; I think there is a spectrum from abstract to concrete

Interface (very abstract)
Abstract class
Ordinary (Concrete) class
Final class
Enum member (read-only: very concrete).

Members of an enum are very concrete; they cannot be changed and must be regarded as read-only. You could add "immutable class" and "abstract class with no abstract methods" to that spectrum if you wish.
 
reply
    Bookmark Topic Watch Topic
  • New Topic