若父类为Human,代码如下
public abstract class Human {
public String name;
public int age;
public abstract void say();
public String toString() {
return "Human [name=" + name + ", age=" + age + "]";
}
}
子类如下,
public class Chinese extends Human {
String name = "小明";
int age = 15;
public void say() {
System.out.println("讲国语");
}
public String toString() {
return "Chinese [age=" + age + "]";
}
}
测试类
public class test {
public static void main(String[] args) {
Human one = new Human();//为什么这一行就报错了呢?
one.say();
Human man= new Chinese();
System.out.println(man);
}
}
qq_青枣工作室_0
Someone0123