| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice Test
Share
medium Solved by 2 students
Java Inheritance and Object Instantiation
< Prev
Next >

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);

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Not enough data yet to show leaderboard.

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy