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

Consider the following class declarations.

public class FruitBasket {
   private int appleCount;
  FruitBasket () {
    appleCount = 1;
   }
  FruitBasket(int count) {
    appleCount = count;
   }
   public int getAppleCount () {
    return appleCount;
   }
}
public class AppleBag extends FruitBasket {
  AppleBag () {
    super(3);
  }
}

Which of the following code segments will compile without error?

A

FruitBasket f1 = new AppleBag(2);

B

AppleBag a2 = new FruitBasket();

C

AppleBag a1 = new AppleBag(4);

D

FruitBasket f2 = new AppleBag();

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

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

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