继承关系类问题?

若父类为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);

}

}


华林0
浏览 1373回答 2
2回答

qq_青枣工作室_0

你的Human是抽象类,不能new的。

Someone0123

Human one = new Chinese()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android
Java