Subclassing and Inheritance: A Challenge

While gas and diesel cars continue to improve their use of fuel, your customers are demanding that you model a hybrid car. Your job is to create a HybridCar class that inherits from Car and adds a method to return the number of miles until the car’s battery and fuel are empty. You can name this method –(float)milesUntilEmpty.

Hint

Don’t forget to track the miles per gallon (MPG) so you can calculate the distance until the car is empty. For example, the 2013 Toyota Prius hybrid gets 42MPG. If there were 10 gallons left in the tank, the car would have a theoretical range of 402 miles until the tank was empty.

Think about it for a few minutes.

Do you have a solution worked out?

Go to the following section ...

Get Learning iOS Development: A Hands-on Guide to the Fundamentals of iOS Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.