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.
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()!
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.