Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
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 n1 = new NovelCollection(10);

D

NovelCollection n2 = new Bookshelf();

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total 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|FAQ