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

Consider the following class definitions.

public class Vehicle {
   private int maxSpeed;
  Vehicle() {
    maxSpeed = 10;
   }
  Vehicle(int speed) {
    maxSpeed = speed;
  }
   public int getMaxSpeed() {
    return maxSpeed;
   }
}
public class Bicycle extends Vehicle {
  Bicycle() {
    super(15);
  }
}

Which of the following code snippets will compile without error?

A

Bicycle b1 = new Bicycle(20);

B

Vehicle v2 = new Bicycle(10);
int speed = v2.getMaxSpeed();

C

Bicycle b2 = new Vehicle();

D

Vehicle v3 = new Vehicle(30);
int speed = v3.getMaxSpeed();

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