A class can inherit from only one abstract class but it can inherit from (implement) multiple interfaces.
Abstract class can have abstract as well as non-abstract members, but in an interface all members are abstract by definition.
Abstract class has to provide default implementation of its non-abstract members. But interface cannot provide any implementation for any of its members.
A class deriving from an interface has to implement all members of an interface, whereas a class deriving from an abstract class has to implement only the abstract members of the base class and may or may not implement the non-abstract members (which are already implemented in the abstract base class).
The default implementation of the non-abstract members is present in the abstract class and so need not be implemented in the child classes.
In case the child class of abstract class decides to implement the non-abstract members of the abstract class, then that derived class member will override the corresponding base class member with same signature.
Abstract class can have private, protected or public members, but in an interface all the members are public by default.
Abstract class is used to define central functionality e.g., vehicle class is abstract base class for car, truck, bus classes.
Interface is used to impart peripheral functionality e.g., Human class implements IWalkable, IEatable, ISee etc.
Abstract class can have state, so it can have fields. Interface has no state so it cannot have fields, it can have only properties.
Abstract class can have abstract as well as non-abstract members, but in an interface all members are abstract by definition.
Abstract class has to provide default implementation of its non-abstract members. But interface cannot provide any implementation for any of its members.
A class deriving from an interface has to implement all members of an interface, whereas a class deriving from an abstract class has to implement only the abstract members of the base class and may or may not implement the non-abstract members (which are already implemented in the abstract base class).
The default implementation of the non-abstract members is present in the abstract class and so need not be implemented in the child classes.
In case the child class of abstract class decides to implement the non-abstract members of the abstract class, then that derived class member will override the corresponding base class member with same signature.
Abstract class can have private, protected or public members, but in an interface all the members are public by default.
Abstract class is used to define central functionality e.g., vehicle class is abstract base class for car, truck, bus classes.
Interface is used to impart peripheral functionality e.g., Human class implements IWalkable, IEatable, ISee etc.
Abstract class can have state, so it can have fields. Interface has no state so it cannot have fields, it can have only properties.
No comments:
Post a Comment