I can make this code work without an object as input parameter for the abstract method. For example, if I make the input parameter for the printInformation() method in person and emp as printInformation(int x) it works.
The moment I make the input parameter as an object for printInformation() method as shown below, it throws an error
emp is not abstract and does not override abstract method
printInformation(person) in person class emp extends person{ ^
abstract class person{
abstract void printInformation(person p);
}
class emp extends person{
emp(){
System.out.println("This is a emp constructor");
}
void printInformation(emp e){
System.out.println("This is an emp");
}
}
class entity{
public static void main(String args[]){
emp employeeObject = new emp();
employeeObject.printInformation(employeeObject);
}
}
Your interface has a function defined like this:
Your class has a function defined like this:
Those are not the same functions. Java considers the second one a new overloaded method, not an implementation of the method from the interface. Since the class
empisn’t declared abstract, but hasn’t provided an implementation for the abstract methodvoid printInformation(person), it is erroneous.