给定以下接口和实现类:
public interface MyInterface {
public String getSomething ();
}
public class MyImplementation implements MyInterface {
@Override
public String getSomething () {
return "Someting";
}
public String getOtherThing () {
return "otherThing";
}
}
然后是一些客户端代码:
MyInterface objectViaMyInt = new MyImplementation();
objectViaMyInt.getSometing(); //WORKS, OF COURSE
objectViaMyInt.getOtherThing(); //DOESNT WORK, OF COURSE
objectViaMyInt.toString(); // WORKS TOO
所以,我想我理解这个的精神。..每个对象都是一个对象,应该继承那些基本方法。但这实际上是如何工作的?似乎它不能遵循继承和基于接口(类型)的访问的正常规则。. .