This is one of the toughest and trickiest question in java language. You may also know that only classes in java are inherited from java.lang.Object class. Interfaces in java don’t inherit from Object class. They don’t have default parent like classes in java. But, following two cases may surprise you. Case 1 : If an interface does not extend Object class, then why we can call methods of Object class on interface variable like below ? interface A { } class InterfaceTest { public static void main(String[] args) { A a = null; a.equals(null); a.hashCode(); a.toString(); } } Case 2 : If an interface does not extend Object class, then why the methods of Object class are visible in interface.? interface A { @Override public boolean equals(Object obj); @Override public int hashCode(); @Override public String toString(); } Explanation : Here is the answer, for every public method in Object class, there is an implicit abstract and public method declared in every interface which does not have di...
Technology - Marketing - Stocks - Views