M
Michael Preminger
I have defined and Interface
public interface HasChildren{
public int getNumberOfChildren();
public void setNumberOfChildren(int numberOfChildren);
}
and let a class, Student, implement it, like this:
class Student extends Person implements HasChildren{
public String toString(){
//....
}
}
In a test class I have a method:
public void giveBirth(HasChildren hc){
}
hc has no access to other methods defined in Student except the two
methods defined in HasChildren, which I understand.
To my surprise I see that the object hc has access to the method
toString(), even though it is not part of the interface definition.
This seem to be the case also for other methods inherited from class Object
The way I understand, interfaces are not descendent of any
superinterface by default. How does class Object come in there?
Thanks
Michael
Michael
public interface HasChildren{
public int getNumberOfChildren();
public void setNumberOfChildren(int numberOfChildren);
}
and let a class, Student, implement it, like this:
class Student extends Person implements HasChildren{
public String toString(){
//....
}
}
In a test class I have a method:
public void giveBirth(HasChildren hc){
}
hc has no access to other methods defined in Student except the two
methods defined in HasChildren, which I understand.
To my surprise I see that the object hc has access to the method
toString(), even though it is not part of the interface definition.
This seem to be the case also for other methods inherited from class Object
The way I understand, interfaces are not descendent of any
superinterface by default. How does class Object come in there?
Thanks
Michael
Michael