Are interfaces also inherited from Object class?

interfaces not inherited from object class and there’s no common or root interface which implicitly inherited by all interfaces either.

Note: For each public method in Object class, there’s an implicit abstract and public method declared in each interface which doesn’t have direct super interfaces. This standard is defined by JLS (Java Language Specification) as

“If an interface has no direct super interfaces, then the interface implicitly declares a public abstract member method m with signature s, return type r, and throws clause t corresponding to each public instance method m with signature s, return type r, and throws clause t declared in Object, unless a method with the same signature, same return type, and a compatible throws clause is explicitly declared by the interface.”

Please check the below example how Object class methods are available in interface: Example

interface Test
{   
    @Override
    public boolean equals(Object obj);
 
    @Override
    public int hashCode();
 
    @Override
    public String toString();
}
public class Main
{
    public static void main(String[] args)
    {
        Test test = null;
 
        System.out.println(test.equals(null));
 
        System.out.println(test.hashCode());
 
        System.out.println(test.toString());
    }
}

Output

Exception in thread "main" java.lang.NullPointerException  
        at Main.main(Main.java:25)

Java interview questions on Inheritance

Please follow and like us:
Content Protection by DMCA.com