Differences between abstract class and interface OOPs concepts.

Asked 26-Aug-2021
Viewed 452 times

1 Answer


0

Abstract Class
1. Abstract class is a class, which is built by abstract keyword.
2. This class can’t be instantiated ie that can’t create an object.
3. Abstract class contains the abstract and non-abstract methods.
4. We need to declare an abstract method in the abstract class by using the abstract keyword.
5. An abstract class has a constructor.
Syntax
abstract class class-name{
    abstract datatype function-name();
}

Interface
1. An interface not a class, which is built by interface keyword.
2. The interface can’t be instantiated but also create the reference variable.
3. Interface always contains the abstract method.
4. We don’t need to declare the abstract method in the interface because the interface method is by default the abstract method.
5. An interface doesn’t have a constructor.
Syntax
access-modifier interface interface-name{

    datatype method-name();
}


Abstract class

public abstract class Shape{
    public abstract void draw();
}

Interface

public interface Paintable{
    void paint();
}