Java 类的继承中出现已定义类型错误
运行结果及报错内容
package chapter7;
class Shape { }
class Square extends Shape{}
class Circular extends Shape{}
public class Demo6 {
public static void draw(Shape s) {
if (s instanceof Square) {
System.out.println("zhengfangxing");
}else if(s instanceof Circular) {
System.out.println("yuanxing");
}else {
System.out.println("shape");
}
}
public static void main(String[] args) {
draw(new Shape());
draw(new Square());
draw(new Circular());
}
}
报错内容
class Square extends Shape{}
class Circular extends Shape{}
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/793094000666161.png "#left")
我想要达到的结果