Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice TestPractice Test
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 b2 = new Vehicle();

B

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

C

Bicycle b1 = new Bicycle(20);

D

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

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

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

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