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
NovelCollection n1 = new NovelCollection(10);
B
Bookshelf b1 = new NovelCollection(15);
C
NovelCollection n2 = new Bookshelf();
D
Bookshelf b2 = new NovelCollection();
int novels = b2.countBooks();
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 1 | 1 | 0m 00s | 100 |
| #2 | zgj07310417 | 0 | 1 | 0m 50s | -60 |
| #3 | suhanakochhar006 | 1 | 1 | 9m 29s | -469 |
Items per page:
10
1 – 3 of 3
APFIVE