This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes interface and abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "interface and abstract class" Watch "interface and abstract class" New topic
Author

interface and abstract class

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
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 ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
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.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Also have a look at our FAQ: Interface vs abstract class


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
James Basller
Ranch Hand

Joined: Sep 07, 2008
Posts: 58
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.
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
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.


be a well encapsulated person, don't expose your privates, unless you public void getWife()!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: interface and abstract class
 
Similar Threads
abstract class Vs interface
abstract class
Interface problems...
Java interface
forcing implementing methods