Abstract Vs Interface
Abstract Class
- It can have abstract and non-abstract methods.
- Doesn't support multiple inheritance.
- It can have final, non-final, static and non-static variables.
- Provide the implementation of interface.
- The abstract keyword is used to declare abstract class.
- An abstract class can extend another Java class and implement multiple Java interfaces.
- It can be extended using keyword "extends".
- It can have class members like private, protected, etc.
Example :
public abstract class Shape
{
public abstract void draw();
}
Interface
- It can have only abstract methods.
- Supports multiple inheritance.
- It has only static and final variables.
- Can't provide the implementation of abstract class.
- The interface keyword is used to declare interface.
- It can extend another Java interface only.
- It can be implemented using keyword "implements".
- Members of a Java interface are public by default.
Example :
0 Comments