| Interfaces provide a form of multiple inheritance. A class can extend only one other class. Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc. A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class. Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast. .......................................................................... (1) An abstract class may contain complete or incomplete methods. Interfaces can contain only the signature of a method but no body. Thus an abstract class can implement methods but an interface can not implement methods. (2) An abstract class can contain fields, constructors, or destructors and implement properties. An interface can not contain fields, constructors, or destructors and it has only the property's signature but no implementation. (3) An abstract class cannot support multiple inheritance, but an interface can support multiple inheritance. Thus a class may inherit several interfaces but only one abstract class. (4) A class implementing an interface has to implement all the methods of the interface, but the same is not required in the case of an abstract Class. (5) Various access modifiers such as abstract, protected, internal, public, virtual, etc. are useful in abstract Classes but not in interfaces. (6) Abstract classes are faster than interfaces. ............................................................................... ABSTRACT CLASS: 1) we can't create object of abstract class. 2) we can declare a variable. 3) we can make normal method and abstract method. 4) we can't make method body with abstract method. 5) in derived class we can use abstract method by override keyword. 6) we can't use multiple inheritance in abstract class. 7) Absrtact class can be extended by only one class; Interface can be implemented by more than one class; ie. class can inherit only one abstract class
8)Abstract classes can inherit interfaces while interfaces cannot inherit abstract classes but class can implement more than one interface. 9) The members of the interface are public with no implementation. Abstract classes can have protected parts,static methods, etc.
10)An abstract class can contain fields, constructors, or destructors and implement properties. An interface can not contain fields, constructors, or destructors and it has abstractmethod,property's signature but no implementation etc. |
0 comments:
Post a Comment