Do interfaces have toString method?

Object has a toString() method, so everything (except primitive types) has a toString() method. Java will treat anything, even an empty interface, as having all the methods of Object, because it always does.


The the Java Documentation says...

When an interface has no direct SuperInterface, it will create abstract public method for all those public methods present in the Object class.

This is why you are able to call the toString() method on the interface reference


Class C implements My but it also extends Object, as all objects eventually do in their inheritance tree.

The Object class does have the method toString(), along with a number of others.


Any Object has a toString() method. Anything that would implement an interface will implicitly extend Object, so will also have a toString() method.

Tags:

Java

Interface