Why Java Interfaces Cannot Have Constructor But Abstract Classes Can Have? Last Updated : 29 Aug, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Prerequisite: Interface and Abstract class in Java. A Constructor is a special member function used to initialize the newly created object. It is automatically called when an object of a class is created. Why interfaces can not have the constructor? An Interface is a complete abstraction of class. All data members present in the interface are by default public, static, and final. All the static final fields should be assigned values at the time of declaration, otherwise it will throw compilation error saying “variable variable_Name not initialized in default constructor”.The methods inside the interface are by default public abstract which means the method implementation cannot be provided by the interface itself, it has to be provided by the implementing class. Therefore, no need of having a constructor inside the interface.A constructor is used to initializing non-static data members and as there are no non-static data members in the interface, there is no need of constructorMethods present in the interface are only declared not defined, As there is no implementation of methods, there is no need of making objects for calling methods in the interface and thus no point of having constructor in it.If we try to create a constructor inside the interface, the compiler will give a compile-time error. Java // Java program that demonstrates why // interface can not have a constructor // Creating an interface interface Subtraction { // Creating a method, by default // this is a abstract method int subtract(int a, int b); } // Creating a class that implements // the Subtraction interface class GFG implements Subtraction { // Defining subtract method public int subtract(int a, int b) { int k = a - b; return k; } // Driver Code public static void main(String[] args) { // Creating an instance of // GFG class GFG g = new GFG(); System.out.println(g.subtract(20, 5)); } } Output15 In the above program, we have created an interface Subtraction which defines a method subtract(), whose implementation is provided by the class GFG. In order to call a method, we need to create an object, since the methods inside the interface by default public abstract which means the method inside the interface doesn't have the body. Therefore, there is no need for calling the method in the interface. Since we cannot call the methods in the interface, there is no need for creating the object for interface and there is no need of having a constructor in it. Why abstract classes have a constructor? The main purpose of the constructor is to initialize the newly created object. In abstract class, we have an instance variable, abstract methods, and non-abstract methods. We need to initialize the non-abstract methods and instance variables, therefore abstract classes have a constructor.Also, even if we don't provide any constructor the compiler will add default constructor in an abstract class.An abstract class can be inherited by any number of sub-classes, thus functionality of constructor present in abstract class can be used by them.The constructor inside the abstract class can only be called during constructor chaining i.e. when we create an instance of sub-classes. This is also one of the reasons abstract class can have a constructor. Java // A Java program to demonstrates // an abstract class with constructors // Creating an abstract class Car abstract class Car { // Creating a constructor in // the abstract class Car() { System.out.println("car is created"); } } // A class that extends the // abstract class Car class Maruti extends Car { // Method defining inside // the Maruti class void run() { System.out.println("Maruti is running"); } } class GFG { public static void main(String[] args) { Maruti c = new Maruti(); c.run(); } } Outputcar is created Maruti is running Comment More infoAdvertise with us Next Article Constructor in Java Abstract Class D dishajindgar Follow Improve Article Tags : Java Computer Subject Java-Abstract Class and Interface java-interfaces Practice Tags : Java Similar Reads Constructor in Java Abstract Class Constructor is always called by its class name in a class itself. A constructor is used to initialize an object not to build the object. As we all know abstract classes also do have a constructor. So if we do not define any constructor inside the abstract class then JVM (Java Virtual Machine) will g 4 min read Why Enum Class Can Have a Private Constructor Only in Java? Every enum constant is static. If we want to represent a group named constant, then we should go for Enum. Hence we can access it by using enum Name. Enum without a constructor: enum Day{ SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY; } Enum with a constructor: enum Size { SMALL("Th 2 min read Can We Instantiate an Abstract Class in Java? Abstract class, we have heard that abstract class are classes which can have abstract methods and it can't be instantiated. We cannot instantiate an abstract class in Java because it is abstract, it is not complete, hence it cannot be used.Example 1Java// Java program to demonstrate abstract class / 3 min read Difference Between Abstract Class and Interface in Java In object-oriented programming (OOP), both abstract classes and interfaces serve as fundamental constructs for defining contracts. They establish a blueprint for other classes, ensuring consistent implementation of methods and behaviors. However, they each come with distinct characteristics and use 9 min read Why a Constructor can not be final, static or abstract in Java? Prerequisite: Inheritance in Java Constructor in java is a special type of method which is different from normal java methods/ordinary methods. Constructors are used to initialize an object. Automatically a constructor is called when an object of a class is created. It is syntactically similar to a 6 min read Difference between Abstract Class and Concrete Class in Java Abstract Class: An abstract class is a type of class in Java that is declared by the abstract keyword. An abstract class cannot be instantiated directly, i.e. the object of such class cannot be created directly using the new keyword. An abstract class can be instantiated either by a concrete subclas 5 min read Like