Open In App

How to Resolve a java.lang.AbstractMethodError in Java?

The java.lang.AbstractMethodError is a runtime error in Java that occurs when a class lacks the implementation of the abstract method declared in one of its interfaces or abstract parent classes. This error signifies a mismatch between the expected and actual class hierarchy.

Syntax:

public interface MyInterface {
    void myMethod();
}

public class MyClass implements MyInterface {
    // Missing implementation of myMethod
}

Program to Resolve a java.lang.AbstractMethodError in Java

The java.lang.AbstractMethodError occurs when a class attempts to invoke an abstract method that should have been implemented by the concrete subclass but isn’t.

Below is the Program to Resolve a java.lang.AbstractMethodError:




interface GFG {
    void myMethod();
}
  
// Class implementing the interface
// And providing the implementation
class myClass implements GFG {
    // Implementation of abstract method
    public void myMethod() {
        System.out.println("Implementation of myMethod");
    }
    public static void main(String[] args) {
        // Creating an instance of MyClass
        myClass obj = new myClass();
        
        // Calling the implemented method
        obj.myMethod();
    }
}

Output:

Implementation of myMethod

Explanation of the above Program:

Article Tags :