What is the difference between "abstract Class" and "interface" in java ?
Main Difference between abstract class and interface are ....
Abstract Class is used for Base Class implementation for all the Class whereas interface is used for property of base Class.
Example : Animal, Bird, tiger, fish. All are Animal as abstract class
& having properties eat same for all but fly, run and swim is
different properties. so we can put eat as abstract method in abstract
class and fly, run & swim used as interface.
The difference between abstract class & interface are as under
1) An abstract class can provide complete code whereas interface cannot provide any code at all
2) In abstract class, a class may extend only one abstract class whereas a class may implement several interfaces.
3) An abstract class can have non abstract methods. whereas all methods of an interface are abstract.
4) An abstract class can have instance variables. whereas interface cannot have instance variables
5) An abstract class can contain constructors. Whereas interface cannot contain constructors.
6) Abstract class are fast. Whereas interface are slow .
No comments:
Post a Comment