Java Inheritance and Object Instantiation
Consider the following class definitions.
public class Bookshelf {
private int bookCount;
Bookshelf () {
bookCount = 5;
}
Bookshelf(int count) {
bookCount = count;
}
public int countBooks() {
return bookCount;
}
}
public class NovelCollection extends Bookshelf {
NovelCollection() {
super(8);
}
}
Which of the following code segments will compile without error?
A
Bookshelf b1 = new NovelCollection(15);
B
Bookshelf b2 = new NovelCollection();
int novels = b2.countBooks();
C
NovelCollection n2 = new Bookshelf();
D
NovelCollection n1 = new NovelCollection(10);
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE