interface Computer
{
int Max = 100;
void speak(String s);
int f(int x);
//float g(float x, float y);
}
abstract class A implements Computer
{



}
class B extends A
{
public void f(int x);
{

}
public void speak(String s)
{
System.out.println(s);
}

}
public class Demo3
{
public static void main(String []args)
{
B b = new B();
}
}编译出错。。
求原因。

解决方案 »

  1.   

    public void f(int x)函数重载,不能改变返回值的类型,应该是:public intf(int x)
      

  2.   

    class B extends A
    {
        public int f(int x) {
    return 0;
    }
        public void speak(String s)
        {
            System.out.println(s);
        }
        
    }
    public class Demo3
    {
        public static void main(String []args)
        {
            B b = new B();
        }
    }
      

  3.   

    同上。 你interface Computer 里f()函数返回是int类型,但Class B里返回void。。