This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

interface and abstract class  RSS feed

 
Ranch Hand
Posts: 588
  • Mark post as helpful
  • send pies
  • 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: 60127
188
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 60127
188
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!