| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice TestPractice Test
About Exam
medium Solved by 4 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

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

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1kaisuki11 0m 00s 100
#2zgj0731041701 0m 50s -60
#3suhanakochhar00611 9m 29s -469
Items per page:
10
1 – 3 of 3
No comments yet. Be the first to comment!

AI Tutor

How can I help?

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