哪位达人帮偶看看java多继承的报错。。。

来源:百度知道 编辑:UC知道 时间:2024/07/05 05:52:31
我的代码如下
--------------------

interface Father{
void sth();
}

interface Son1 extends Father{
void doSth();
}

interface Son2 extends Father{
void doSth2();
}

class Ss implements Son1,Son2{
public void doSth(){
System.out.println ("s11");
}
public void doSth2(){
System.out.println ("s22");
}
public void sth(){
System.out.println ("sth...");
}
}

public class Test{
public static void main (String[] args) {
Father s = new Ss();
s.sth();
s.doSth();
}
}
--------------------
报如下错误:

找不到符号doSth()
-----------------------
这个该怎么解决啊。多谢了。

因为s是Father接口的对象,它并不存在doSth()方法,改正错误很简单,改成Ss s=new Ss();就好了,这样再调用doSth()就不会报错了

father指向Ss的对象,然后调用dosth不可以
他自己都没有dosth