【发布时间】:2015-02-27 19:52:24
【问题描述】:
我有这样的课:
public abstract class Book {
public abstract double retailPrice();
private String title, author, ISBN;
private double price;
public Book() {
title = "";
author = "";
ISBN = "";
price = 0.00;
}
public Book(String title, String author, String ISBN, double price) {
this.title = title;
this.author = author;
this.ISBN = ISBN;
this.price = price;
}
public String getTitle() {
return title;
}
在数组中包含 Textbook 类的对象(如下所示):
public class Textbook extends Book {
private String course;
@Override
public double retailPrice() {
return super.getPrice() + (super.getPrice() * .10);
}
public Textbook() {
course = "";
}
public Textbook(String course) {
this.course = course;
}
public String getCourse() {
return course;
}
public void setCourse(String course) {
this.course = course;
}
}
我的数组中充满了以下对象:
Book[] books = new Book[100];
books[i] = new Textbook(courseName);
当我使用 books[i]. 调用我的数组时,唯一可用的方法是 Textbook 的继承类 (Book) 的 getTitle()。
所以我的问题是,如何访问 Textbook 类的 getCourse() 函数?
【问题讨论】:
标签: java inheritance methods