【发布时间】:2018-10-28 03:07:19
【问题描述】:
我没有包含 main 函数,因为它是空的。我正在尝试从父类访问私有变量 name 到子类,但随后它会抛出错误消息。它会是如果你能帮助我很好。顺便说一句,我是 JAVA 新手。
public class Author {
private String name;
private String email;
private char gender;
public Author(String name,String email,char gender)
{
this.name=name;
this.email=email;
this.gender=gender;
}
protected String getName()
{
return name;
}
//protected String
}
public class Book extends Author {
private String name;
private String authorname;
private double price;
private int qtyInStock;
Book(String name,Author a,double price,int qtyInStock)
{
this.name=name;
this.authorname=a.getName(); //Error
this.price=price;
this.qtyInStock=qtyInStock;
}
}
错误信息:
隐式超级构造函数 HelloWorld.Author() 未定义。必须 显式调用另一个构造函数。
【问题讨论】:
标签: java oop inheritance