Java 继承错误及解决方法:Dog 类继承 pet 类
在代码中,Dog 类继承了 pet 类,但是在 import 语句中,引入了错误的类名。应该使用正确的类名 'import com.chinasofti.week1.day04.pet;'。
此外,在 Dog 类中,getName() 方法的返回类型应为 String 而不是 StringBuffer,应该修改为 'String getName()'。
另外,在 getName() 方法中,调用了 name() 方法,但是在代码中没有定义 name() 方法,应该修改为调用父类的 getName() 方法,即 'super.getName()'。
原文地址: http://www.cveoy.top/t/topic/nZxh 著作权归作者所有。请勿转载和采集!